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

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


当前回答

您可以使用:

git reset HEAD@{1}

此命令将删除您没有 Git 日志的错误执行 。

其他回答

您可以从本地仓库撤销您的承诺 。 请遵循以下方案 。

在下面的图像中, 我检查“ 测试” 分支( 使用 Git 命令)git checkout -b test)作为本地检查状态(使用 Git 命令)git status地方分支中没有任何可承诺的。

Enter image description here

在下一个图像图像中,您可以看到这里的图像 我做了一些修改过滤器1. txt然后用一些信息(使用 Git 命令) 将文件添加到中继区, 并用一些信息( 使用 Git 命令) 来进行更改git commit -m "Doing commit to test revert back").

"-m 用于发送信件"

Enter image description here

在下一个图像中,您可以看到您承诺的日志,无论您承诺什么(使用 Git 命令)git log).

Enter image description here

所以在以上图像中,您可以看到每个承诺的承付代号, 以及您现在的执信信息, 无论您想要返回或撤消的复制件, 即实施 ID 并击中下面的 Git 命令,git revert {"paste your commit id"}示例:

git revert 9ca304ed12b991f8251496b4ea452857b34353e7

Enter image description here

我恢复了上次的承诺。 现在, 如果您检查您的 Git 状态, 您可以看到修改后的文件过滤器1. txt并且尚未承诺。

Enter image description here

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

git log

然后

git reset <the previous co>
#1) $ git commit -m "Something terribly misguided" 
#2) $ git reset HEAD~                              

[必要时编辑文件]

 #3) $ git add .
#4) $ git commit -c ORIG_HEAD  

每次我需要撤销承诺/承诺时,我要做的是:

  1. git reset HEAD~<n>/ 上次承诺的数量, 我需要撤销

  2. git status/ 可选。 所有文件现在都红色( 未预设 ) 。

  3. 现在,我可以添加并只承诺我所需要的文件 :

  • git add <file names> & git commit -m "message" -m "details"
  1. 可以选择:我可以将其它文件的更改(如果需要的话) 推回到它们以前的状态, 并进行退票:
  • git checkout <filename>
  1. 如果我已经把它推向了遥远的起源, 之前:
  • git push origin <branch name> -f用 -f来强迫推

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

你会遇到这个问题:

$ 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 .