当处于交互式rebase的中间时,例如git rebase -i HEAD~12
添加/编辑一些提交时,我常常对我正在编辑的提交感到困惑,特别是当存在合并冲突时:
> git status
rebase in progress; onto 55d9292
You are currently rebasing branch 'master' on '55d9292'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git reset HEAD <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both modified: file
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
如何清楚了解当前状态中涉及的所有补丁?例如,什么是基本补丁,我正在"挑选"哪个补丁,合并冲突来自哪个补丁?
在交互式 rebase 中,例如
git rebase -i HEAD~12
添加/编辑一些提交时,我经常对我正在编辑哪个提交感到困惑
在 Git 2.17(2018 年第 2 季度)中,新的“ --show-current-patch
”选项提供了一种面向最终用户的方式,可以在“ git rebase
”(和“ git am
”)因冲突而停止时应用差异。
请参阅Nguy?n Thái Ng?c Duy ( ) 的commit fbd7a23、commit 6633529、commit 984913a(2018 年 2 月 11 日)。
帮助者:Tim Landscheidt ( )。(由Junio C Hamano合并-- --在提交 9ca488c 中,2018 年 3 月 6 日)pclouds
scfc
gitster
rebase:引入和使用伪引用 REBASE_HEAD
新命令
git rebase --show-current-patch
对于查看与当前 rebase 状态相关的提交很有用。
然而,有些人可能会发现其git show
背后的“ ”命令过于局限。
您可能想要增加上下文行,做一个忽略空格的差异......对于这些高级用例,用户可以使用新的伪 ref 执行他们想要的任何命令
REBASE_HEAD
。这也有助于显示停止提交的来源,这从实现
--show-current-patch
.
另请参阅Git 2.26(2020 年第二季度)中的新git rebase/am --show-current-patchd=diff
模式。
如果有冲突,可以运行git show
查看最后应用的提交。
然后,当打开冲突文件时,冲突将一方面显示上次应用的提交时文件的状态,另一方面显示当前正在应用的提交时文件的状态。
\n\n例子:
\n\n我创建了一个带有文件“a”的存储库。我的第一次提交是创建文件:
\n\nJohn@debian-John: ~/tmp/test (master #) \xe2\x9c\x96 (1)\n> touch a\nJohn@debian-John: ~/tmp/test (master #) \xe2\x9c\x94\n> git add a\nJohn@debian-John: ~/tmp/test (master +) \xe2\x9c\x94\n> git commit -m initial\n[master (root-commit) 298299e] initial\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 a\n
Run Code Online (Sandbox Code Playgroud)\n\n然后,我修改了该文件并将其提交为“commit1”:
\n\nJohn@debian-John: ~/tmp/test (master) \xe2\x9c\x94\n> echo aaa >a\nJohn@debian-John: ~/tmp/test (master *) \xe2\x9c\x94\n> git add a\nJohn@debian-John: ~/tmp/test (master +) \xe2\x9c\x94\n> git commit -m commit1\n[master 90b49f8] commit1\n 1 file changed, 1 insertion(+)\n
Run Code Online (Sandbox Code Playgroud)\n\n然后,再次执行提交“commit2”:
\n\nJohn@debian-John: ~/tmp/test (master) \xe2\x9c\x94\n> echo bbb >>a\nJohn@debian-John: ~/tmp/test (master *) \xe2\x9c\x94\n> git add a\nJohn@debian-John: ~/tmp/test (master +) \xe2\x9c\x94\n> git commit -m commit2\n[master 14d798e] commit2\n 1 file changed, 1 insertion(+)\n
Run Code Online (Sandbox Code Playgroud)\n\n然后我重新调整以删除 commit1:
\n\nJohn@debian-John: ~/tmp/test (master) \xe2\x9c\x94\n> git rebase -i HEAD^^\nAuto-merging a\nCONFLICT (content): Merge conflict in a\nerror: could not apply 14d798e... commit2\n\nWhen you have resolved this problem, run "git rebase --continue".\nIf you prefer to skip this patch, run "git rebase --skip" instead.\nTo check out the original branch and stop rebasing, run "git rebase --abort".\n\nRecorded preimage for \'a\'\nCould not apply 14d798e... commit2\n
Run Code Online (Sandbox Code Playgroud)\n\n无法应用 Commit2,因为其上下文已更改(commit1 丢失)。请注意其中error: could not apply 14d798e... commit2
包含 commit2 的哈希值。在冲突中,如果我逃跑git show
,我会得到:
John@debian-John: ~/tmp/test (master *+|REBASE-i 1/1) \xe2\x9c\x96 (1)\n> git show\ncommit 298299e3fb4e75c50aaa346c9f57c3b8885726f7 (HEAD)\nAuthor: John Doe <john@doe>\nDate: Fri Jul 21 15:59:01 2017 +0100\n\n initial\n\ndiff --git a/a b/a\nnew file mode 100644\nindex 0000000..e69de29\nJohn@debian-John: ~/tmp/test (master *+|REBASE-i 1/1) \xe2\x9c\x94\n> git status\ninteractive rebase in progress; onto 298299e\nLast command done (1 command done):\n pick 14d798e commit2\nNo commands remaining.\nYou are currently rebasing branch \'master\' on \'298299e\'.\n (fix conflicts and then run "git rebase --continue")\n (use "git rebase --skip" to skip this patch)\n (use "git rebase --abort" to check out the original branch)\n\nUnmerged paths:\n (use "git reset HEAD <file>..." to unstage)\n (use "git add <file>..." to mark resolution)\n\n both modified: a\n\nno changes added to commit (use "git add" and/or "git commit -a")\n
Run Code Online (Sandbox Code Playgroud)\n\na的内容是:
\n\nJohn@debian-John: ~/tmp/test (master +|REBASE-i 1/1) \xe2\x9c\x94\n> cat a\n<<<<<<< HEAD\n=======\naaa\nbbb\n>>>>>>> 14d798e... commit2\n
Run Code Online (Sandbox Code Playgroud)\n\n其中 HEAD 是最后应用的提交(初始),第二部分是应用失败的提交。
\n\n我希望它会有所帮助。
\n