git - reorder安全地提交 [英] git - reorder commits safely
问题描述
我发现通过 git rebase -i
重新排序提交可能不会在处理已删除文件时产生相同的最终结果树 - 并且可能会在没有警告或错误消息。
请按照以下顺序提交
A - Add foo1
B - 添加foo2
C - 删除foo2,添加Foo3
使用 git rebase -i
重新排列从ABC到ACB的提交结果foo2出现在HEAD中。
有没有一种方法可以重新排序提交声音如果重排序会改变最终的结果树?
我认为 git rebase
在内部使用 git am
来应用补丁。我没有看到任何相关的指向 git am
的参数,这些参数可用于在删除不存在的文件时强制执行失败,这是我认为需要的。我需要修补git源代码才能得到我想要的结果吗?
-
git stash save --include-untracked
的简单组合一个干净的状态 -
git rev-parse HEAD
获取当前提交的散列值 -
git rebase
做实际工作 -
git checkout the_previously_saved_hash。
to恢复出厂前的状态 -
git clean -fd
可以清除所有多余的文件 -
git commit -m通过rebase引入更改
如果rebase没有引入任何更改(可以忽略此失败),则可能会失败 -
git stash pop
重新引入隐藏的污染元素
应该做...我想我会尽快制作一个这样的脚本,因为它也是我需要的。
I've discovered that reordering commits via
git rebase -i
may not produce the same end result tree when dealing with removed files - and may do so with no warning or error message.Take the following sequence of commits
A - Add foo1 B - Add foo2 C - Remove foo2, Add Foo3
Using
git rebase -i
to reorder the commits from A-B-C to A-C-B results in foo2 being present in the HEAD.Is there a way to reorder commits that barks if the reorder would alter the final resulting tree?
I think
git rebase
is internally usinggit am
to apply patches. I don't see any relevant args togit am
that could be used to force a fail upon removal of a non-existent file, which is what I think would be needed. Do I have to patch the git source code to get what I want?解决方案You can rebase, compare the result, and then possibly reset to the old state. A simple combination of
git stash save --include-untracked
to get into a clean stategit rev-parse HEAD
to get the hash of the current commitgit rebase
to do the real workgit checkout the_previously_saved_hash .
to restore the state before rebasinggit clean -fd
to get rid of all superfluous filesgit commit -m "Undoing the changes introduces by rebase."
which may fail if the rebase introduced no changes (this failure can be silently ignored)git stash pop
to re-introduce the stashed-away "pollution"
should do... I guess I'll try to make a script like this soon as it's something I need as well.
这篇关于git - reorder安全地提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!