如何以非交互方式在 Git 中重新排序提交
哪些非交互式 git 命令实现了从之前到之后的更改?
之前:
A---B---C---D
之后:
A---C'---B'---D'
What non-interactive git command(s) achieve the change from Before to After?
Before:
A---B---C---D
After:
A---C'---B'---D'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的情况下,您可以重新设置交互式基准:
git rebase -i HEAD~4
然后您可以重新排序您的选择例如,让我们向我们的分支添加另外三个文件:
您的简短日志将是:
如果您想将 B 与 C 重新排序:
您只需将它们重新排序为:
完成编写后,请参阅简短日志:
您可以通过重新排序对所有提交执行相同的操作。就像所见即所得,这很酷:)
In your case, you can rebase interactive:
git rebase -i HEAD~4
Then you can just reorder your picksFor example lets add three more files to our branch:
Your shortlog will be:
If you want to reorder B with C:
You just re-order them to be:
After you're done writing, see the shortlog:
You can do the same thing with all the commits by re-ordering. It is like what you see is what you get, which is pretty cool :)
试试这个:
可能有一种使用 git rebase 的方法,但我不太明白。
Try this:
There may be a way with
git rebase
, but I didn't really understand it.请参阅如何以非交互方式运行 git rebase --interactive? 以非交互方式使用 git rebase --interactive 。
然后,如果您有重新排序提交的正式标准,则可以编写脚本,请参阅例如 真正展平 a git merge 按原始提交日期重新排序提交。
See How do I run git rebase --interactive in non-interactive manner? for using git rebase --interactive in non-interactive manner.
Then, if you have formal criteria for reordering commits, you can script that, see for example Really flatten a git merge to reorder commits by the original commit date.
如果您想在脚本中重新排序提交并且不想处理提交哈希,那么这似乎是一个通用解决方案(基于 Paŭlo Ebermann 的答案):
我假设运行此命令序列两次a row 会将提交树恢复到之前的状态,除了更改已更改的提交哈希值。
If you want to reorder commits in a script and don't want to deal with the commit hashes, then this seems to work as a general solution (based on Paŭlo Ebermann 's answer):
I assume that running this sequence of commands twice in a row will restore the commit tree to what it was before, except for changing the changed commit hashes.