我无意中把错误的文件给了Git, 但还没有把承诺推到服务器上。

我如何从当地存储库撤销这些承诺?


当前回答

要重置上一个修订版, 请永久删除所有未承诺的更改 :

git reset --hard HEAD~1

其他回答

在我的案子中,我无意中犯了一些我不想犯的案卷。所以我做了以下的,它奏效了:

git reset --soft HEAD^
git rm --cached [files you do not need]
git add [files you need]
git commit -c ORIG_HEAD

用 gitk 或 git 日志 -- stat 校验结果

这里是网站: 哦,该死,混蛋!

这里有许多解密的秘方 如何在Git 中解决事情。其中一些是:

哦,该死,我需要改变 信息在我的最后一次承诺!

git commit --amend
# follow prompts to change the commit message

哦,我无意中把什么东西 给了主人 本来该在全新的树枝上!

# Create a new branch from the current state of master
git branch some-new-branch-name
# Remove the commit from the master branch
git reset HEAD~ --hard
git checkout some-new-branch-name
# Your commit lives in this branch now :)

视觉演播室代码使得这很容易。

为了完整起见,我将提出前几个答复所忽略的一个明显明显的方法。

由于承诺没有被推,遥控器没有改变,因此:

删除本地仓库。 克隆远程仓库 。

有时候,如果你的高贵的Git客户告别(看着你,伊吉特),这有时是必要的。

别忘了重新承诺上次推后保存的更改 。

通过下列方式查看日志来查找上次承诺的散列代码 :

git log

然后

git reset <the previous co>