What are the differences between double-dot “..” and triple-dot “…” in Git diff commit ranges?

前端 未结 5 596
广开言路
广开言路 2020-11-22 12:33

What are the differences between the following commands?:

git diff foo master   # a 
git diff foo..master  # b
git d         


        
5条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 13:10

    git diff foo master Diff between the top (head) commits of foo and master.

    git diff foo..master Another way of doing the same thing.

    git diff foo...master Diff from the common ancestor (git merge-base foo master) of foo and master to tip of master. In other words, shows only the changes that master branch has introduced since its common ancestor with foo.

    This example from GitHub explains when to use the two:

    For instance, if you create a ‘dev’ branch and add a function to a file, then go back to your ‘master’ branch and remove a line from the README, and then run something like this:

    $ git diff master dev
    

    It will tell you that a function was added from the first file and a line was added to the README. Why? Because on the branch, the README still has the original line, but on ‘master’ you’ve removed it - so directly comparing the snapshots looks like ‘dev’ added it.

    What you really want to compare is what ‘dev’ has changed since your branches diverged. To do that, Git has a nice little shorthand:

    $ git diff master...dev
    

提交回复
热议问题