Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
66 views
in Technique[技术] by (71.8m points)

How to get the changes on a branch in Git

What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is:

git log $(git merge-base HEAD branch)..branch

The documentation for git-diff indicates that git diff A...B is equivalent to git diff $(git-merge-base A B) B. On the other hand, the documentation for git-rev-parse indicates that r1...r2 is defined as r1 r2 --not $(git merge-base --all r1 r2).

Why are these different? Note that git diff HEAD...branch gives me the diffs I want, but the corresponding git log command gives me more than what I want.

In pictures, suppose this:

         x---y---z---branch
        /
---a---b---c---d---e---HEAD

I would like to get a log containing commits x, y, z.

  • git diff HEAD...branch gives these commits
  • however, git log HEAD...branch gives x, y, z, c, d, e.
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the context of a revision list, A...B is how git-rev-parse defines it. git-log takes a revision list. git-diff does not take a list of revisions - it takes one or two revisions, and has defined the A...B syntax to mean how it's defined in the git-diff manpage. If git-diff did not explicitly define A...B, then that syntax would be invalid. Note that the git-rev-parse manpage describes A...B in the "Specifying Ranges" section, and everything in that section is only valid in situations where a revision range is valid (i.e. when a revision list is desired).

To get a log containing just x, y, and z, try git log HEAD..branch (two dots, not three). This is identical to git log branch --not HEAD, and means all commits on branch that aren't on HEAD.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...