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

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


当前回答

使用此命令 :

git checkout -b old-state number_commit

其他回答

使用此命令

git checkout -b old-state 0d1d7fc32

为了撤销最后的本地承诺, 在不丢弃其改变的情况下, 我有一个便用的别名~/.gitconfig

[alias]
  undo = reset --soft HEAD^

然后,我简单地使用git undo这是超容易记住的。

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

git reset --hard HEAD~1

如果您想要撤销在回邮中的第一个承诺

你会遇到这个问题:

$ git reset HEAD~
fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

发生错误的原因是,如果最后一次承诺是存储处的初始承诺(或没有父/母),则不存在 HEAD~ 。

解决方案

如果您想要重置“ master” 分支上唯一的承诺

$ git update-ref -d HEAD
$ git rm --cached -r .

认为我们有code.txt 代码转换器。我们对其文件进行一些修改并做出承诺。我们可以以三种方式撤销这一承诺,但首先你应该知道什么是阶段文件...git status此文件将以绿色颜色显示, 如果此文件没有被预设用于承诺, 则会以红色显示 :

enter image description here

意思是,如果您进行更改,此文件中的更改就不会保存。 您可以在您的舞台上添加此文件git add code.txt然后承诺更改:

enter image description here

撤消上次承诺 :

  1. 如果我们想要在不做任何其他更改的情况下撤销承诺,

    git reset --soft HEAD^

    enter image description here

  2. 如果我们想要撤销承诺及其变化( ) 。这是危险的,因为你的改变会失去),我们可以使用

    git reset --hard HEAD^

    enter image description here

  3. 如果我们想要撤销承诺,从舞台上删除变化, 我们可以使用

    git reset --mixed HEAD^或以短或短形式git reset HEAD^

    enter image description here