如何为一个提交指定一个或多个父代 [英] How to specify one or several parents for a commit
问题描述
我已经完成了合并,并且创建了新的合并提交。然后,我将软重置分支一提交以保留具有分辨率的所有文件,恢复一个分辨率,现在我想使用所有这些文件重新创建合并提交。我有两个来自原始合并提交的父项哈希,并且希望在创建新提交时模拟合并提交时以某种方式指定这些父项。是否有可能?
I've done a merge and the new merge commit has been created. Then I soft reset the branch one commit back to preserve all files with resolutions, reverted one resolution and now I want to create merge commit again using all those files. I have two parent's hashes from the original merge commit and want to somehow specify these parents when creating a new commit to emulate merge commit. Is it possible?
推荐答案
除了 Mark Adelsberger的答案,有一个直接的方法可以用两个管道命令来做到这一点:
Besides Mark Adelsberger's answer, there's a direct way to do this with two plumbing commands:
tree=$(git write-tree) # write updated index to new tree
commit=$(git commit-tree -p $firstparent -p $secondparent -F /tmp/msgfile)
(其中 / tmp / msgfile
包含提交信息;请注意,您可以使用 -m
来指定消息文本,或 -F -
从stdin读取消息,在这种情况下,您可以 git log --pretty =%B $ hash
来提取原始提交信息,并将其传递给 git commit-tree
)。
(where /tmp/msgfile
contains the commit message; note that you can use -m
to specify message text, or -F -
to read the message from stdin, in which case you could git log --pretty=%B $hash
to extract the original commit message and pipe that to git commit-tree
).
完成提交后,您可以 git merge --ff-only
或 git reset --hard 给它,例如:
Once you have the commit you can git merge --ff-only
or git reset --hard
to it, e.g.:
git merge --ff-only $commit
不过,我只是想知道y ou表示:
I wonder, though, just what you mean by:
还原了一个分辨率
reverted one resolution
<在所有情况下,结果就是通常所说的邪恶合并:合并的结果并非基于其输入。无论这种合并是否真的是邪恶的,甚至是一个坏主意,都是一个意见问题,但以后再生产肯定很难,而且似乎需要一个好的提交信息。
and in all cases the result is what is generally called an "evil merge": a merge whose result is not based on its inputs. Whether such a merge is truly evil, or even just a bad idea, is a matter of opinion, but it's certainly hard to reproduce later, and seems to call for a good commit message.
这篇关于如何为一个提交指定一个或多个父代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!