4

我正在使用gitkand查看提交历史记录,git log并试图查看特定提交是如何到达某个分支的。我可以看到历史中的提交,所以我知道它们在那里。

我想了解的是它们是如何合并的(它们应该保留在自己的分支上)。这是一个非常大的项目,在有问题的提交和分支的当前状态之间有数百个提交,所以我无法清楚地破译有限的 DAG gitk,并且提交在其他分支中被掩盖并合并和提交消息。

为此,我一直在尝试:

gitk {sha1hashIDstring}..branch_name
gitk {sha1hashIDstring}..branch_name --ancestry-path
git log {sha1hashIDstring}..branch_name --reverse
git log {sha1hashIDstring}..branch_name --merges --reverse
git log {sha1hashIDstring}..branch_name --ancestry-path --reverse
git log {sha1hashIDstring}..branch_name --ancestry-path --merges --reverse

我不理解结果。我只想查看包含相关特定提交的项目,以便我清楚地看到它是如何进入相关分支的。我该怎么做?

例子

我正在寻找的东西,gitk最好但git log就足够了:

Message       Author         Date         #commit that merged branch z into current branch
Message       Author         Date         #commit that merged branch y into branch z
Message       Author         Date         #commit that merged branch x into branch y
Message       Author         Date         #commit that merged {sha1hashIDstring} commit/branch a into branch x
Message       Orig_Author    Date         #{sha1hashIDstring} original commit, on branch a

更多信息

我还没有看到任何答案,所以如果没有答案,我会开始赏金,但也许我没有正确解释这个问题(我愿意接受改进和澄清的建议)。

这样做的驱动力是我可以看到提交本身,并且有人告诉我它不应该在某个分支上。这是我所看到的:

Message       Orig_Author    Date         #{sha1hashIDstring} commit
Message       Orig_Author    Date         #Merged into branch test_dec14 (includes original commit)
...
Message       Author         Date         # unrelated commits
Message       Author         Date         # more unrelated commits
# Stuff happened here ??? everything I do gives me hundreds of things here 
# Not all of them related to the {sha1hashIDstring} commit
# No idea how to see only the ones that are
...
Message       Author         Date         # final commit on test_jan15 branch

有人告诉我,除非它们被释放,否则test_dec14不应提交 in test_jan15,因此 {sha1hashIDstring} 提交不应该在test_jan15,但确实如此。我想知道为什么,它是如何到达那里的,以及是谁把它放在那里的。

4

5 回答 5

2

对于您问题的后半部分,“它是如何进入当前分支的?”,请查看git-when-merged

这是一个 Python 脚本,根据它的自述文件:

查找何时将提交合并到一个或多个分支中。找到将 COMMIT 带入指定 BRANCH(es) 的合并提交。具体来说,在包含 COMMIT 作为祖先的 BRANCH 的第一父历史上查找最旧的提交。

{sha1hashIDstring}在确定提交何时合并到test_jan15分支中时,这听起来像是您正在寻找的内容。

于 2015-02-03T17:56:45.837 回答
1

这是一个经典案例git bisect。bisect 帮助您跟踪错误。在您的情况下,您只需寻找一个 commitId (它被放错了错误的分支)。

Bisect 是一个非常简单但功能强大的工具。

http://git-scm.com/docs/git-bisect http://hashrocket.com/blog/posts/finding-failure-git-bisect

希望它会帮助你。

于 2015-02-02T01:37:30.873 回答
1

您是否尝试过 git log 的“--decorate”选项?

我的 .gitconfig 中有这个别名:

[别名]

        k = log --graph --oneline --abbrev-commit  --decorate

它显示了一个与 gitk 显示的相似的图表,除了分支中的最新提交之外,分支名称“装饰”。


或者

--

也试试tig。它比 gitk 提供更多信息(根据我的用法;))。请参阅http://gitready.com/advanced/2009/07/31/tig-the-ncurses-front-end-to-git.html一次。我认为这两种解决方案都会为您提供所需的结果。

于 2015-02-03T17:57:14.587 回答
1

我用谷歌搜索了一些东西并为你找到了一些东西。功劳归于#vonC

git when-merged [OPTIONS] COMMIT [BRANCH...]

查找何时将提交合并到一个或多个分支中。找到将 COMMIT 带入指定 BRANCH(es) 的合并提交。

具体来说,在包含 COMMIT 作为祖先的 BRANCH 的第一父历史上查找最旧的提交。

git 什么分支

发现提交在哪个分支上,或者它是如何到达指定分支的 这是一个来自 Seth Robertson 的 Perl 脚本,看起来很有趣:

SYNOPSIS

git-what-branch [--allref] [--all] [--topo-order | --date-order ]
[--quiet] [--reference-branch=branchname] [--reference=reference]
<commit-hash/tag>...
OVERVIEW

告诉我们(默认情况下)提交和合并的最早因果路径,以导致请求的提交到达指定的分支。如果直接在命名分支上进行提交,那显然是最早的路径。

最早的因果路径是指最早合并到命名分支的路径,按提交时间(除非指定 --topo-order )。

表现

如果许多分支(例如数百个)包含提交,系统可能需要很长时间(对于 linux 树中的特定提交,探索一个分支需要 8 秒,但有超过 200 个候选分支)来跟踪路径每次提交。选择要检查的特定 --reference-branch --reference 标记将快数百倍(如果您有数百个候选分支)。

**EXAMPLES**
 # git-what-branch --all 1f9c381fa3e0b9b9042e310c69df87eaf9b46ea4
 1f9c381fa3e0b9b9042e310c69df87eaf9b46ea4 first merged onto master using the following minimal temporal path:
   v2.6.12-rc3-450-g1f9c381 merged up at v2.6.12-rc3-590-gbfd4bda (Thu May  5 08:59:37 2005)
   v2.6.12-rc3-590-gbfd4bda merged up at v2.6.12-rc3-461-g84e48b6 (Tue May  3 18:27:24 2005)
   v2.6.12-rc3-461-g84e48b6 is on master
   v2.6.12-rc3-461-g84e48b6 is on v2.6.12-n
   [...]
于 2015-02-03T18:23:27.550 回答
0

我知道这没有用“github”标记 - 但如果项目在那里,则 Blame 或 History 的视觉风格(查看特定文件时文件头中的按钮)可以更容易地跟踪事情发生的时间。

不确定这是否真的解决了这个(非常)具体的问题 - 但它可能会帮助其他有类似问题的人发现这个问题......

于 2015-02-04T11:16:51.963 回答