在rebase过程中,我经常想要查看当前正在应用的提交的消息,以帮助理解合并冲突。
我曾经运行过:
我曾经运行过:
$ cat .git/rebase-apply/message
这会很好地为我提供所需的内容。然而,在我的新机器上运行git v2.20.1时,在rebase期间该文件不再存在。
在哪里可以获取当前正在应用的提交信息(当rebase因合并冲突而暂停时)?
$ cat .git/rebase-apply/message
这会很好地为我提供所需的内容。然而,在我的新机器上运行git v2.20.1时,在rebase期间该文件不再存在。
在哪里可以获取当前正在应用的提交信息(当rebase因合并冲突而暂停时)?
git rev-parse --git-path rebase-merge/message
和git 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
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
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
GIT_PATH_FUNC
行。其中之一是您的rebase-merge/message
文件。无论您是进行交互式rebase、git rebase -m
还是git rebase -s strategy
,此文件都应存在于相应的工作树依赖路径中。对于非交互式git rebase
,该文件应该在rebase-apply/msg
中。git am --show-current-patch
它显示提交信息以及更多内容。
.git/rebase-apply/msg-clean
等效的文件,我猜你不会满足于仅知道没有这样的文件,你需要一种实际获取消息的方法。 - David Z