Correct way to compare same file in different bran

2019-07-16 21:55发布

问题:

This question How to compare files from two different branches? deals with the issue of comparing the same file in different branches, but several answers are given and all of them appear to have some caveat.

These are the ways presented:

1- git difftool mybranch master -- myfile.cs

(several people complain about this not working for them; it did in my case)

2- git difftool branch1:file branch2:file

(a comment says "Using the colons is not really a great way")

3- git difftool branch1 branch2 path/to/file

Which one is the recommended way?

回答1:

  • Your options 1. and 3. are exactly the same, apart from the fact that using -- disambiguates it as a path.

    This may be important when the path doesn't currently exist (in either branch or locally).

  • Now, I don't know what's so bad about the colon notation. It's the most versatile, because you can even do

    git difftool branch1:file_name1.txt branch2:path/to/some_otherfilename.txt
    

If it's just about the typing involved (I guess this is what the commenter means with "not great") then:

git difftool {branch1,branch2}:file

Or even

git difftool branch{1,2}:file

Would do nicely in bash



标签: git branch diff