Git - 删除旧的提交,它的更改从未发生过 [英] Git - delete older commit like it and its changes never happened

查看:153
本文介绍了Git - 删除旧的提交,它的更改从未发生过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除较旧的提交,因为我必须将它分离为2个提交。
所以 a5b4cd 的变化与 2a0d40e + a8bb836

I want to delete older commit, because I had to separate it to 2 commits. So changes, that are at a5b4cd are same like changes in 2a0d40e + a8bb836.

2a0d40e Add sending
a8bb836 Add parsing
a5b4cbd Add sending and parsing     <--- I want to delete this
f6063ac First commit

我试过这里有一些 git rebase -i fixup ,但每次都会将这个已删除提交的更改添加到另一个提交并且我不想要。

I tried some git rebase -i and fixup here, but everytime, it will add changes from this "deleted" commit to another commit and that I dont want.

推荐答案

不要使用fixup。只需在互动式重新绑定期间删除该行。

Don't use fixup. Simply remove that line during your interactive rebase.

这将足以让该提交被删除。

That will be enough for that commit to be dropped.

但是,准备好必须强制推送( git push --force ),这可能会在公共分支机构出现问题。

But then be prepared to have to force push (git push --force) which can be problematic on public branches.

另一个选项是 git revert (如果您只想取消该提交,而不是完全从历史记录中删除它)

Another option would be git revert (if you just want to cancel that commit rather than remove it from the history completely)


在重新绑定之前,当我想将它们分开时,我使用File3和File4获得了Commit2。然后我想分开它,所以我删除了File4,添加了Commit3(只是使用File1和File3),然后添加了File4并使Commit4成为可能。

Before rebasing when I wanted to separate them I got Commit2 with File3 and File4. Then I wanted to separate it, so I have deleted File4, add Commit3 (just with File1 and File3), then added File4 and make Commit4.



然后解决方案是不同的:在提交4(与所有文件),做一个

Then the solution is different: While at Commit 4 (with all your files), do a

git reset --soft Commit1
git add File3
git commit -m "Add File3"
git add File4
git commit -m "Add File4"

这篇关于Git - 删除旧的提交,它的更改从未发生过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆