gpt4 book ai didi

git - git rebase 是否有相当于 "git apply --reject"的值?

转载 作者:太空狗 更新时间:2023-10-29 14:19:26 24 4
gpt4 key购买 nike

我想使用 git rebase获取一系列提交并将它们应用于不同的根提交。例如,

git rebase --onto root start finish

start 获取提交至 finish基于 root .

当 git 无法干净地应用提交时,它会更新文件以显示这样的冲突(来自 git 手册的示例):

       Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let's go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.

程序员将文件编辑为新分支中应有的内容,然后运行git --rebase continue。继续添加来自源的提交。

但是,当文件在root之间有大量变化时和 start ,可能有很多这样的行,它们可能很难解释。在这种情况下,人们可能更愿意将“failed hunks”输出到一个文件中,这样人们就可以通读原始提交中的更改(手动对正在更改的文件进行必要的更改,然后运行 ​​git rebase --continue 来继续添加提交)。

--reject git apply 的选项这样做:

   --reject
For atomicity, git apply by default fails the whole patch and does
not touch the working tree when some of the hunks do not apply.
This option makes it apply the parts of the patch that are
applicable, and leave the rejected hunks in corresponding *.rej
files.

这也是 patch 的行为程序 - 所以我可以通过首先使用 git show 输出提交来获得我想要的东西, 然后用 patch 应用它.但是,当涉及许多提交时,这并不方便。

有没有办法用 git rebase 做到这一点? (或另一个 git 命令)?

最佳答案

您可以在逐个提交的基础上执行类似的操作。

当发生 merge 冲突时,git 会给出如下消息:

CONFLICT (content): Merge conflict in file.c
Failed to merge in the changes.
Patch failed at 0004 Changes to file
The copy of the patch that failed is found in:
/home/g/src/project/.git/rebase-apply/patch

如果 file.c 由于显示文件中的 merge 冲突而被破坏,您可以将文件恢复到提交之前的状态

git reset file.c
git checkout file.c

然后你可以运行

patch -p1 </home/g/src/project/.git/rebase-apply/patch

它的输出看起来像

patching file file.c
Hunk #2 FAILED at 1133.
Hunk #3 FAILED at 1167.
Hunk #4 FAILED at 1201.
Hunk #5 FAILED at 1241.
Hunk #6 FAILED at 1251.
Hunk #7 succeeded at 1324 (offset 6 lines).
Hunk #8 FAILED at 1325.
Hunk #9 succeeded at 2142 (offset 11 lines).
Hunk #10 succeeded at 2163 (offset 11 lines).
Hunk #11 succeeded at 2181 (offset 11 lines).
Hunk #12 succeeded at 2279 (offset 11 lines).
Hunk #13 succeeded at 2299 (offset 11 lines).
Hunk #14 succeeded at 2412 (offset 11 lines).
Hunk #15 succeeded at 2508 (offset 11 lines).
Hunk #16 succeeded at 2531 (offset 11 lines).
Hunk #17 succeeded at 2540 (offset 11 lines).
Hunk #18 succeeded at 2581 (offset 11 lines).
Hunk #19 succeeded at 2599 (offset 11 lines).
Hunk #20 succeeded at 2611 (offset 11 lines).
Hunk #21 succeeded at 2629 (offset 11 lines).
Hunk #22 succeeded at 2637 (offset 11 lines).
Hunk #23 succeeded at 2668 (offset 11 lines).
Hunk #24 succeeded at 2677 (offset 11 lines).
Hunk #25 succeeded at 2805 (offset 11 lines).
Hunk #26 succeeded at 2871 (offset 11 lines).
Hunk #27 succeeded at 2911 (offset 11 lines).
Hunk #28 succeeded at 3028 (offset 11 lines).
Hunk #29 succeeded at 3085 (offset 11 lines).
Hunk #30 succeeded at 3117 (offset 11 lines).
Hunk #31 succeeded at 3557 (offset 11 lines).
Hunk #32 succeeded at 3572 (offset 11 lines).
Hunk #33 succeeded at 4773 (offset 11 lines).
Hunk #34 succeeded at 4807 (offset 11 lines).
Hunk #35 succeeded at 4859 (offset 11 lines).
6 out of 35 hunks FAILED -- saving rejects to file file.c.rej

然后手动修改file.c.rej,然后运行

git add -u
git rebase --continue

继续。

关于git - git rebase 是否有相当于 "git apply --reject"的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23047330/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com