如何删除Github和本地上的最后n个提交? [英] How to delete the last n commits on Github and locally?
问题描述
我正在尝试从我的GitHub存储库中删除最后2个提交。我已经尝试按照建议的方式此处: git push -f origin HEAD ^^:master
。
I'm trying to delete the last 2 commits from one of my GitHub repositories. I've tried as suggested here : git push -f origin HEAD^^:master
. It seems that it works, as the last two commits are removed.
然后我用 git rebase -i HEAD〜2 $从本地存储库中删除了它们。 c $ c>。我删除与这些提交相关的行,并使用
git log
检查它们是否已正确删除。
Then I deleted them from my local repository with git rebase -i HEAD~2
. I remove the lines that are related to those commits, and check with git log
that they are correctly removed.
之后,我在我的本地存储库中进行一些更改,进行新的提交,然后推送到GitHub。问题是,在我的GitHub帐户中,我尝试删除了前两次提交。
After that, I make some changes in my local repository, make a new commit, and push to GitHub. The problem is that, in my GitHub account, I have the previous two commits that I've tried to delete.
我认为问题出在我的本地存储库中,因为如果我克隆自己的将Github存储库移至我的本地资源,并在此处进行一些更改,当我推送新的提交时,那些旧的提交不会被推送到GitHub。
I think the problem is in my local repository, because if I clone my Github repository to my local and make some changes here, when I push a new commit those old commits aren't pushed to GitHub.
推荐答案
要在本地删除最后两个提交,我建议使用:
To remove the last two commits locally I'd suggest using:
git reset --hard HEAD^^
Rebase是一种完全不同的操作,在这里无济于事。
Rebase is a completely different operation that won't help you here.
这篇关于如何删除Github和本地上的最后n个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!