Git 撤消上次提交

标签 git

我在两个分支之间以错误的方式 merge 。然后我运行了以下命令:

git reset --hard HEAD^

我现在回到了之前的提交(这是我想去的地方)。这是正确的做法吗?

错误的提交仍在存储库中,这样可以吗?还是我应该做其他事情将其从存储库中删除?

我还没有推送或提交任何其他内容。

最佳答案

这是正确的做法。

您可以执行 git gc 来垃圾收集断开连接的提交,但这不是必需的。

关于Git 撤消上次提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2897669/

相关文章:

git - 如何在 "git push -u <remote-name> <remote-branch-name>"中自动使用本地分支名称

git - git push origin master 上出现错误 - 错误 : RPC failed; curl 56 SSL read: error:00000000:lib(0):func(0):reason(0), errno 10053 fatal:

git - 使用 intelliJ 将 SVN 更改为 GIT

git - 添加托管在 Github 上的私有(private) Maven 存储库作为 Gradle 中的依赖项

git - TortoiseGit 找不到 git.exe

Git,致命的 : The remote end hung up unexpectedly

git - 为所有用户启用 git merge 我们的驱动程序

git - git在哪里存储有关存储库来源的信息

git - 如何从git中的提交ID中提取提交文件?

git - 防止进入密码钥匙串(keychain)