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

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

问题描述

我正在尝试从我的 GitHub 存储库之一中删除最后 2 个提交.我已经按照此处的建议进行了尝试:gitpush -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 从我的本地存储库中删除它们.我删除了与这些提交相关的行,并使用 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屋!

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