git log
、git blame
和 git bisect
命令时出现了奇怪的行为。 一位朋友告诉我可以通过在 git log
命令中添加 --full-history
参数来解决这个问题。 我想知道是否有类似的方法可以修复 git blame
和 git bisect
的问题。请随意使用此存储库自行查看问题:https://dl.dropboxusercontent.com/u/1927707/problematic_repo.7z。以下是其日志:$ git log --graph
* commit b7a8d7aa001d06eb7491ab5fb447a8dd3aa421a8
| Author: Ram Rachum <ram@rachum.com>
| Date: Tue Apr 19 17:45:01 2016 +0300
|
| adding more to some-file
|
* commit 0aa833916e908ea93902a6c4c227f9a884a1bcef
|\ Merge: 2413945 3068c7d
| | Author: Ram Rachum <ram@rachum.com>
| | Date: Tue Apr 19 17:44:31 2016 +0300
| |
| | Merge branch 'master' into development
| |
| * commit 3068c7d2548f1798b6840f73b13a649937339f28
| | Author: Ram Rachum <ram@rachum.com>
| | Date: Tue Apr 19 16:02:27 2016 +0300
| |
| | Adding sugar to coffee
| |
* | commit 24139451ab954b1f0a9ef616775a3dba0ac81669
|/ Author: Ram Rachum <ram@rachum.com>
| Date: Tue Apr 19 16:01:28 2016 +0300
|
| Creating some-file
|
* commit cf02fbbc40104cd02eea4c7c6f134ef1fd7b5661
Author: Ram Rachum <ram@rachum.com>
Date: Tue Apr 19 16:00:47 2016 +0300
Create coffee
在第一次提交时,添加了文件
coffee
。在提交3068c7d
中,我向coffee
文件添加了一行“sugar”。但是,然后我将这个分支合并到development
分支中,在合并过程中出现了错误,导致“sugar”行被删除,使得coffee
文件变为空。接着,又添加了另一个提交b7a8d7a
进行无关的更改,以确保情况稳定。
现在我看着我的咖啡,发现里面没有加糖。我清楚地记得在我的咖啡里加了糖。我运行git log coffee
,并得到以下输出:
$ git log coffee
commit cf02fbbc40104cd02eea4c7c6f134ef1fd7b5661
Author: Ram Rachum <ram@rachum.com>
Date: Tue Apr 19 16:00:47 2016 +0300
Create coffee
就是这样。 git log
没有显示添加该文件后又删除它的合并提交和原始提交,这两个提交非常重要。
我为此问题苦恼了一个小时,因为它发生在一个巨大的企业存储库中,手动查找提交非常困难。
我还尝试使用 git bisect
和 git blame
来确定这两个提交,但这两个工具都忽略了这两个提交。在我完成所有 git bisect bad
和 git bisect good
操作后,git bisect
将我指向错误的提交。
然后,正如我在开头所说的,一位朋友向我指出了 --full-history
标志:
$ git log --full-history --graph coffee
* commit 0aa833916e908ea93902a6c4c227f9a884a1bcef
|\ Merge: cf02fbb 3068c7d
| | Author: Ram Rachum <ram@rachum.com>
| | Date: Tue Apr 19 17:44:31 2016 +0300
| |
| | Merge branch 'master' into development
| |
| * commit 3068c7d2548f1798b6840f73b13a649937339f28
|/ Author: Ram Rachum <ram@rachum.com>
| Date: Tue Apr 19 16:02:27 2016 +0300
|
| Adding sugar to coffee
|
* commit cf02fbbc40104cd02eea4c7c6f134ef1fd7b5661
Author: Ram Rachum <ram@rachum.com>
Date: Tue Apr 19 16:00:47 2016 +0300
Create coffee
这让我很高兴,因为它显示了两个相关的提交,一个添加了sugar,另一个合并了它,所以我的问题解决了。
但是我真的希望知道如何让git bisect
和git blame
表现得更好。 有人知道吗?
blame
似乎接受了标志,但看起来它并没有改变任何东西。尝试使用git blame --full-history
和git blame --full-history --reverse
都没有显示结果。关于无法打开7z档案的问题,在这里我已经将其转换为zip格式:https://dl.dropboxusercontent.com/u/1927707/foo.zip - Ram Rachumgit blame --reverse HEAD^^^..HEAD --full-history coffee
,但仍然没有得到任何结果。 - Ram RachumJSON
格式,以便您可以仔细查看它们。您可能需要取消注释gitlogg-parse-json.js
文件中的所有注释字段,并删除gitlogg-generate-log.sh
中的--no-merges
以获取所有可用输出。 - Wallace Sidhrée