删除特定提交之前的提交
有没有办法删除指定提交之前的所有提交并将该提交用作初始提交?
Is there a way to remove all commits before a specified commit and use that commit as the initial?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设新的最旧提交的哈希值是 X,我们可以暂时使用“oldroot”和“newroot”:
这将创建一个“newroot”提交,其内容与“oldroot”提交相同,但没有任何父级。然后,它将所有其他分支重新设置为新根,这应该存在于所有其他分支的历史中。
编辑:测试并修复;稍晚一点,精炼一点
Let's say the new oldest commit's hash is X and we can use "oldroot" and "newroot" temporarily:
That will create a 'newroot' commit with the same contents as the 'oldroot' commit, but without any parents. Then, it rebases all the other branches onto the new root, which should be in the history of all of them.
EDIT: tested and fixed; slightly later, refined a bit
更简单的解决方案是,
考虑最初你的分支有提交main,并且你做了一个提交first,现在你还在first<之上做了一个提交second /强>。所以你有这样的情况:
现在你希望将 second 放在 main 之上,而不是放在 first 之上。例如:
您可以简单地执行以下操作,
这将为您提供一个交互式 shell,您可以在其中重新排列提交的顺序或删除您选择的任何提交。
The more easier solution would be,
Consider originally your branch has commit main and you did a commit first, now you also did a commit second on top of first. So you have something like:
Now you want to have second on top of main rather than on top of first. Something like:
You can simply do,
This will give you an interactive shell where you can rearrange the order of commits or remove any commit of your choice.