开发者

How can I diff against a revision of a single file using only the default Git GUI tools?

开发者 https://www.devze.com 2022-12-29 20:22 出处:网络
I want to view the history of a single file, and then compare a single revision from that history against the current version.

I want to view the history of a single file, and then compare a single revision from that history against the current version.

On the command line, this is easy:

  1. Run:

    git log -- <filename>
    
  2. Locate the version you want to compare,

  3. Run:

    git diff <commitid> -- <filename>
    

But how can this be done using only the default Git gui tools, git gui and gitk?

I know of two methods using gitk, but they're both horribly clunky:

Either:

  1. Select the New View option from the View menu,

  2. Type in the full path to your file into the box labelled Enter files and directories to include, one per line,

  3. Locate the version you want to compare by looking at the highlighted items in the top pane, and click on it to select it,

  4. Right-click on the current version and select Diff selected -> this,

Or:

  1. Select Tree in the bottom right-hand pane,

  2. Locate the file you want to look at, right-click on it, and select Highlight this only,

  3. Locate the version you want 开发者_C百科to compare by looking at the highlighted items in the top pane, and click on it to select it,

  4. Right-click on the current version and select Diff selected -> this,

  5. Click on the file in the bottom right-hand pane to jump to it in the diff output, or scroll manually.

Is there a better method than this?


You can launch gitk from the command line and limit its scope to a single file.

You can also limit the output to a set of commits.

For example, to show the changes since <commit> that changed path/to/file, try:

gitk <commit>.. -- path/to/file

See the gitk man page for more details.

0

精彩评论

暂无评论...
验证码 换一张
取 消