简体   繁体   English

当前版本的git diff与分支提交

[英]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? 如何识别“分支提交”(他从中分支的提交)并与当前版本VS的提交进行比较?

The best way to identify the branching commit is to use merge-base: 识别分支提交的最佳方法是使用merge-base:

git merge-base main-branch other-branch

But git provides some other alternatives to do what you need. 但是git提供了其他一些替代方法来满足您的需求。 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 . 此语法将计算main-branchHEAD之间的merge-base,然后向您显示HEAD引入的所有更改。 If your not currently on the branch you want to examine, you can just replace HEAD with the name of the branch: 如果您当前不在要检查的分支上,则只需将HEAD替换为分支的名称即可:

git diff main-branch...other-branch

ProGit has a description of this as well. ProGit也对此进行了描述

To see the changes introduced by a branch with git log , you want to use the two dot notation ( .. ): 要查看git log分支引入的更改,您想使用两个点表示法( .. ):

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. 带有git log的...表示法将显示自合并基础以来在任一分支上引入的所有提交,这不是您想要的。

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; gitk之类的工具可以图形化地显示这种信息。 you can easily copy commit hashes out of them for use with commandline tools. 您可以轻松地从中复制提交哈希,以供命令行工具使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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