如何删除Github上和本地的最后n个提交? [英] How to delete the last n commit on Github and locally?

查看:111
本文介绍了如何删除Github上和本地的最后n个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除我的一个GitHub存储库中的最后2个提交。我尝试了建议这里:git push -f起源HEAD ^^:主人。看起来它是有效的,最后两个提交被删除。

然后我用git rebase -i HEAD〜2从我的本地存储库中删除它们。我删除了与这些提交相关的行,然后使用git log检查它们是否被正确删除。



之后,我对本地存储库进行了一些更改,新的提交和推送到GitHub。问题是,在我的GitHub帐户中,我有前面的两个提交,试图删除。



我认为问题出在我的本地存储库上,因为如果我克隆我的Github存储库到我的本地,并在我推新提交时做一些更改,这些旧提交不会推送到GitHub。



任何想法?

解决方案

在本地删除最后两个提交,我建议使用:

  git reset --hard HEAD ^^ 

重做是一种完全不同的操作这不会帮助你。


I'm trying to delete the last 2 commits in one of my GitHub repositories. I've tried as suggested here : git push -f origin HEAD^^:master. It seems that it works, the last two commits are removed.

Then I deleted them from my local repository with git rebase -i HEAD~2. I remove the lines than are related with those commit, and check with git log that they are correctly removed.

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 commit I've tried to delete.

I think the problem it's 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.

Any idea?

解决方案

To remove the last two commits locally I'd suggest using:

git reset --hard HEAD^^

Rebase is a completely different operation that won't help you here.

这篇关于如何删除Github上和本地的最后n个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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