从 Git 2.17(2018 年 3 月)开始,您不需要使用rebase-apply
.
当“ ”(和“ ”)因冲突而停止时,新的“ --show-current-patch
”选项提供了一种面向最终用户的方式来获得diff
应用。git rebase
git am
请参阅Nguyễn Thái Ngọc Duy ( )的提交 fbd7a23、提交 6633529、提交 984913a(2018 年 2 月 11 日) 。(由Junio C Hamano 合并——在提交 9ca488c中,2018 年 3 月 6 日)pclouds
gitster
am
:添加--show-current-patch
签字人:Nguyễn Thái Ngọc Duy
指向用户$GIT_DIR/rebase-apply
可能会鼓励他们在那里乱搞,这不是一件好事。
有了这个,用户在需要查看补丁时不必将路径保留在某个地方(因为在几个命令之后,路径可能超出回滚缓冲区)。
在“显示当前 git 交互式变基操作”中查看更多信息
例子:
C:\Users\VonC\repo\src>git rebase origin/master
First, rewinding head to replay your work on top of it...
Applying: change code
Using index info to reconstruct a base tree...
M a/src/file
Falling back to patching base and 3-way merge...
Auto-merging a/src/file
CONFLICT (content): Merge conflict in a/src/file
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch' to see the failed patch <======
Patch failed at 0001 change code
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
然后你会得到:
C:\Users\VonC\rep\src>git am --show-current-patch
commit xxx (master)
Author: VonC <vonc@vonc.com>
Date: Mon Nov 4 13:59:18 2019 +0100
change code
diff --git a/a/src/file b/a/src/file
index yyy..zzz 100644
--- a/a/src/file
+++ b/a/src/file
@@ -13,5 +13,5 @@ file: /a/src
content line 1
content line 2
content line 3
content line 4
-content line 5
-content line 6
+content bis line 5
+content bis line 6
“ git am --short-current-patch
”是一种显示已停止步骤的电子邮件的方式,不适合直接喂“ git apply
”(它被设计为一个很好的“ git am
”输入)。
在 Git 2.26(2020 年第一季度)中,它学习了一个仅显示补丁部分的新选项。
请参阅Paolo Bonzini ( ) 的提交 aa416b2、提交 f3b4822、提交 e8ef1e8、提交 bc8620b、提交 62e7a6f(2020 年 2 月 20 日)。(由Junio C Hamano 合并 -- --在提交 0e0d717中,2020 年 3 月 9 日)bonzini
gitster
am
: 支持 --show-current-patch=diff 检索 .git/rebase-apply/patch
报告人:J. Bruce Fields
签字人:Paolo Bonzini
当git am --show-current-patch
在提交 984913a210 (" am
: add --show-current-patch", 2018-02-12, Git v2.17.0-rc0 -- merge列在批次 #7中) 中添加 " " 时, " git am
" 开始将其推荐为替换为.git/rebase-merge/patch
.
不幸的是,这个建议有些误导。例如,如果“”的输出被编码为quoted-printable 或base64,git am --show-current-patch
则不能将其传递给“ ”。git apply
为“ ”添加新模式git am --show-current-patch
以理顺建议。
新模式是diff
:
--show-current-patch[=(diff|raw)]
:
显示git am
因冲突而停止的消息。
如果raw
指定,则显示电子邮件消息的原始内容;如果diff
,仅显示差异部分。
默认为raw
.
和:
am
: 支持--show-current-patch=raw
作为同义词--show-current-patch
签字人:Paolo Bonzini
为了简化工作树操作并避免用户戳入.git
,如果“ git am
”也提供一种复制.git/rebase-merge/patch
到标准输出的模式会更好。
一种可能性是拥有完全独立的选项,例如引入--show-current-message
(for .git/rebase-apply/NNNN
) 和--show-current-diff
(for .git/rebase-apply/patch
),同时可能弃用 --show-current-patch。
这甚至可以消除对系列中前两个补丁的需求。但是,长的公共前缀会阻止使用诸如“ --show
”之类的缩写选项。
因此,我选择将字符串参数添加到--show-current-patch
.