如何搜索git存储库历史记录以查找合并错误? [英] How to search a git repository history to find a merge error?

查看:454
本文介绍了如何搜索git存储库历史记录以查找合并错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们过去的git开发分支中的某个时刻被合并了。然而,错误的合并决定已经完成,因此一些代码并没有将其纳入我们预期的主分支中。 (在最终合并到一个主分支之前有不同分支的多个合并,因此分支和合并历史相当复杂。)

是否有一种简单的搜索方式一个git仓库来确定在哪个合并上做出了错误的决定?

(我已经知道这个特定案例的答案,但是找到它的过程是)b / b
$ b

编辑:git blame证明不充分的原因是该行在合并错误后的某个提交中被触动。

解决方案

如果你知道被git分支合并修改的文件中的一行,你可以做'git blame file。 txt'并确定提交散列号并提交文件中该行的作者。然后你可以通过git日志,并拉出与坏分支合并相关的确切提交。



编辑:
作为对作者评论的回应,如果你正在寻找某一行的消失,然后'git diff'结合grep和二进制搜索可能是你想要的。假设你已经提交了数字0,1,2,3,4,5,6。您知道该行存在于版本0中,但在版本6中消失了。使用'git diff'加上grep来搜索失踪。

  git diff 0 6 | grep' -  line我关心'

第一次迭代,您会看到您关心的行消失。然后你将修订号码减半,然后再试一次

  git diff 0 3 | grep' - 行我关心'

如果grep仍然显示行消失(使用' - '符号),那么您知道该行在版本0到3中消失。如果grep 显示该行消失,则该行在修订4-6中消失。



继续修改一半,直到找到罪魁祸首。


At some point in our past branches of development in git were merged. However, the wrong merge decision was made and therefore some code didn't make it into master branch that we expected would be there. (There were multiple merges of different branches before a final merge to a master branch. So the branching and merging history was fairly complex.)

Is there an easy way to search a git repository to determine on which merge the "wrong" decision was made on?

(I already know the answer for this particular case, but the process of finding it was a bit tedious.)

EDIT: The reason git blame proved inadequate is that the line was touched in a commit sometime after the merge error.

解决方案

If you know a line in a file that was modified by the git branch merge, you can do 'git blame file.txt' and determine the commit hash number and commit author of the line in the file. Then you can go through the git log and pull up the exact commit associated with the bad branch merge.

EDIT: In response to the author's comments, if you're looking for the disappearance of a certain line then 'git diff' combined with grep and binary search could be what you want. let's say you have commit numbers 0,1,2,3,4,5,6. You know that the line existed in revision 0, but disappeared in revision 6. Use 'git diff' plus grep to search for the disappearance.

git diff 0 6 | grep '- line I care about'

The first iteration, you'll see the line you care about disappearing. Then you cut the revision number in half and try again

git diff 0 3 | grep '- line I care about'

If the grep still shows the line disappearing ( with the '-' sign), then you know that the line disappeared in revision 0 to 3. If the grep doesn't show the line disappearing, then the line disappeared in revisions 4-6.

Keep cutting the revisions in half until you find the culprit.

这篇关于如何搜索git存储库历史记录以查找合并错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆