在 git rebase 过程中查看当前提交的信息

5
在rebase过程中,我经常想要查看当前正在应用的提交的消息,以帮助理解合并冲突。
我曾经运行过:
$ cat .git/rebase-apply/message

这会很好地为我提供所需的内容。然而,在我的新机器上运行git v2.20.1时,在rebase期间该文件不再存在。

在哪里可以获取当前正在应用的提交信息(当rebase因合并冲突而暂停时)?


2
好问题,但我能否建议将标题改为“在git rebase期间查看当前提交的消息”,因为这似乎更直接地回答了你想知道的问题?例如,如果没有与.git/rebase-apply/msg-clean等效的文件,我猜你不会满足于仅知道没有这样的文件,你需要一种实际获取消息的方法。 - David Z
好主意 @DavidZ,看起来有人比我更快地完成了它,但这绝对是一个更好的标题,方便后来的搜索者,谢谢! :) - scanny
2个回答

4
TL;DR: 如果你在一个添加的工作树中,请检查git rev-parse --git-path rebase-merge/messagegit rev-parse --git-path rebase-apply/msg。不幸的是,获取这些信息的接口并不稳定。然而,你所寻找的文件在现代Git中仍然存在。随着git worktree的出现,大多数状态信息已经(至少可能)移动了。现在同样存在相同类型的文件,但位置却不确定。要找到其git相对路径名称为P的文件的位置,请使用git rev-parse --git-path P
$ git rev-parse --git-path HEAD
.git/HEAD
$ git worktree add ../git2 --detach
Preparing worktree (detached HEAD 5d826e9729)
HEAD is now at 5d826e9729 Git 2.20
$ (cd ../git2; git rev-parse --git-path HEAD)
[redacted]/git/.git/worktrees/git2/HEAD

从Git 2.13版本开始,可找到rebase信息的两个目录分别是:
rebase-apply
rebase-merge

(一如既往,使用git-path技巧来定位实际的目录或其中的单个文件)。其中的文件最初是对称的,因为代码只是设置了一个状态目录,然后根据需要将文件放入其中。文件集可能会在任何未来的Git版本中发生变化;但是,由于contrib/completion/git-prompt.sh,至少有一些一致性的希望。如果存在,它首先查找rebase-merge内部的内容:

head-name    the branch you were on when you started the rebase
msgnum       how many commits are already done (how far along are you)
end          the total number of commits to do
interactive  if exists, means this is git rebase -i (vs git rebase -m)

如果 rebase-merge 不存在,它会在 rebase-apply 中查找(如果存在),以寻找:
next         how many commits are already done (how far along are you)
last         the total number of commits to do
rebasing     if exists, means this is an ordinary git rebase, in which case:
  head-name    the branch you were on when you started rebasing
applying     if exists, means this is a git am without rebase

如果既不存在变基也不存在应用文件,则提示代码假定“git-am或git-rebase”,而不尝试猜测更多内容。 如果目录都不存在,则提示设置代码会继续检查:
MERGE_HEAD        a merge is in progress
CHERRY_PICK_HEAD  a cherry-pick is in progress
REVERT_HEAD       a revert is in progress
BISECT_LOG        a bisect is in progress

相对于这些内容,序列控制器代码(现在用于除遗留的rebase之外的所有内容,尽管我不确定2.13中它被使用了多少)有更多的内容——请参见源代码中的所有GIT_PATH_FUNC行。其中之一是您的rebase-merge/message文件。无论您是进行交互式rebase、git rebase -m还是git rebase -s strategy,此文件都应存在于相应的工作树依赖路径中。对于非交互式git rebase,该文件应该在rebase-apply/msg中。

1
在2.23版本中,我看到了以下命令:
git am --show-current-patch

它显示提交信息以及更多内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接