问题描述
我只想删除git日志中间的特定提交.它不应该受到以上提交的影响.
I want only to delete a specific commit in the middle of a git log. It shouldn't be affected to above commits.
推荐答案
如果未将提交推送到远程服务器,则可以使用 git rebase
修改git历史记录.
If the commit were not pushed to a remote server, you can use git rebase
to modify the git history.
您可以这样做:
git rebase -i commit-hash^
它将显示提交列表.第一行应该是您要删除的提交.从您编辑的文件中删除该行,然后保存并关闭.
It will show a list of commits. The first line should be the commit you want to delete. Remove that line from the file you edited, save and close.
如果您确实在此之前将其推送到远程服务器,请注意,根据刚从历史记录中删除的提交之前的提交,重写了刚刚删除的提交之后的提交.由于该特定原因,所有提交都被更改,因为您的历史记录刚刚发生了分歧.因此,如果您尝试推动该操作,它将不会很快进行,因此您必须强制执行该操作.
If you did push to a remote server prior to do that, note that the commits after the commit you just deleted were rewritten based on the commit before the one you just deleted from the history. For that particular reason, all of the commits are changed because your history just diverged. So if you try to push that, it won't be fast-forward and you'll have to force the push.
因此,如果您不熟悉 git rebase
,我建议保持分支指向您正在修改历史记录的分支,以防出现问题.
For that reason, if you're not familiar with git rebase
I suggest keeping a branch pointing to the branch you were modifying the history in case something goes wrong.
此外,如果特定的提交在多个分支之间共享,则使一个分支的历史记录分开会导致多个问题,因为您将无法轻松地将一个分支从旧历史记录合并到新历史记录中.它将重复许多提交,并且您在一个分支中删除的提交不会在其他分支中删除.
Also, if that particular commit is shared accross multiple branches, diverging the history of one branch will cause multiple problems as you won't be able to easily merge one branch from the old history to the branch in the new history. It will duplicate many commit and the commit you deleted in one branch won't be deleted in the others.
认为它修改了git历史就像时间旅行.某一时刻的任何更改都会创建一个新的并行Universe.过去更改之后的所有内容实际上都受到您过去所做更改的影响.
Think of it has modifying git history is like time travel. Any change at one point create a new parallel universe. Everything that was after the change in the past really is impacted by the change you did in the past.
这篇关于如何在git日志中间删除仅特定的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!