我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。

我如何解除那些承诺?当地当地仓库?


当前回答

只要在下面执行命令时重置它, 使用git:

git reset --soft HEAD~1

解释:什么什么是git reset基本上reset任何承诺,如果你愿意 回去,如果你把它和--soft键,它将返回,但保留您文件中的更改,所以您可以回到刚刚添加文件的阶段,HEAD是分支的首脑,如果结合了~1(在这种情况下,你们也使用)HEAD^,它会回去 只有一个承诺 你想要什么...

我为您创建了以下图像中的步骤, 详情更多, 包括所有在真实情况下可能发生的步骤, 并承诺执行代码 :

How to undo the last commits in Git?

其他回答

如果您想要永久撤销它, 您克隆了一些仓库 。

犯罪身份可通过以下方式识别:

git log 

然后你们可以做:

git reset --hard <commit_id>

git push origin <branch_name> -f

如果您只是想要丢弃所有本地更改/ 承诺, 使您的本地分支看起来像您从... 开始的源分支...

git reset --hard origin/branch-name

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

git log

然后

git reset <the previous co>
git revert commit

这将产生与您想要返回的承诺相反的变化, 然后再进行这种改变。 我认为这是最简单的方式 。

https://git-scm.com/docs/git-revert

以下是网站:Oh shit, git!.

这里有许多解密的秘方 如何在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 :)