简体   繁体   中英

git diff of current version with branching commit

I have to review code done by someone else in his own branch. He branched weeks ago from our main branch.

Since then, both branches have diverged, and I need to identify which changes he made.

How can I identify the "branching commit" (the commit that he branched from) and diff his current version VS that commit?

The best way to identify the branching commit is to use merge-base:

git merge-base main-branch other-branch

But git provides some other alternatives to do what you need. If you want to see the changes introduced by your current branch, you can use this syntax:

git diff main-branch...HEAD

This syntax will compute the merge-base between main-branch and HEAD , and then show you all the changes introduced by HEAD . If your not currently on the branch you want to examine, you can just replace HEAD with the name of the branch:

git diff main-branch...other-branch

ProGit has a description of this as well.

To see the changes introduced by a branch with git log , you want to use the two dot notation ( .. ):

git log main-branch..HEAD

That will show you the commits introduced by the current branch that are not on the main branch.

The ... notation with git log will show you all commits introduced on either branch since the merge-base, which is not what you want here.

The information is trivially available: the "branching" commit is the last common ancestor of the "review" commit and the "main" commits.

Tools like gitk can show you this sort of information graphically; you can easily copy commit hashes out of them for use with commandline tools.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM