这与我的另一个问题有关:Can't make a replacement ref "permanent" .需要明确的是,无论出于何种原因,git replace --graft
与 git filter-branch
的结合都不起作用。
我需要 merge 三个分支,但是 octopus merge 失败(文件太不相似)所以我全部手动完成(git show branch:file > file
然后启动 meld
).但是,历史很重要,所以我需要记录 branch
是父级。尽管我按照 man 文件和 Stackexchange 上的其他地方(filter-branch
)告诉我的去做,但我无法使替换 refs permentant,我寻求替代方案。
从我现有的问题中可以看出,我的第一个想法是使用替换,但这并没有按预期工作(它们没有被“粘合”)。类似地,git graft
似乎不被建议。此外,如链接问题中所述, Octopus merge 失败。查看 git commit --help
(手册页)一无所获。
请注意,我不是在询问向旧提交添加额外的父项。我在尚未推送的分支的顶端,并且没有提交将此作为父项。
最佳答案
通过在较低的层次上看这个(DO 提交究竟是如何发生的)我看到了一个可爱的网页:https://jwiegley.github.io/git-from-the-bottom-up/1-Repository/4-how-trees-are-made.html .
所以答案是手工完成。
git add file
git write-tree
echo "commit message" | git commit-tree -p branch_A -p branch_B -p branch_C $hash-from-previous-step
git update-ref refs/heads/branch_A $hash-from-previous-step #note I'm on branch_A
瞧!然后我可以编写一个简单的 shell 命令,它将提交消息和其他两个分支作为输入(使用 HEAD
作为第一个父级)。
见鬼,我把它写成了一行。
git add file && git update-ref refs/heads/branch_A $(echo "commit message" | git commit-tree -p branch_A -p branch_B -p branch_C $(git write-tree))
关于git - 强制提交在提交时有额外的 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54729427/