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

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


当前回答

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

你会遇到这个问题:

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

其他回答

取决于您是否已经公开了您的前一次承诺( 插入到您的远程仓库 ) :

如何撤销本地任务

比方说我承诺了当地, 但现在我想取消那个承诺。

git log
    commit 101: bad commit    # Latest commit. This would be called 'HEAD'.
    commit 100: good commit   # Second to last commit. This is the one we want.

要让一切恢复到上次承诺之前的状态 我们需要reset之前的承诺HEAD:

git reset --soft HEAD^     # Use --soft if you want to keep your changes
git reset --hard HEAD^     # Use --hard if you don't care about keeping the changes you made

现在git log将显示我们最后的承诺已被删除 。

如何撤销公开承诺

如果您已经公开了承诺, 您将会想要创建一个新的承诺, 它将“ 撤销” 您对上一个承诺( 当前 HEAD) 所做的更改 。

git revert HEAD

你们的更改将恢复,并准备好你们承诺:

git commit -m 'restoring the file I removed by accident'
git log
    commit 102: restoring the file I removed by accident
    commit 101: removing a file we don't need
    commit 100: adding a file that we need

更多信息,请查看Git Basics - 撤销事情.

您可以使用git revert <commit-id>.

为了得到身份证明 只需使用git log.

撤消上次承诺 :

git reset --soft HEAD^git reset --soft HEAD~

这将撤销最后一项承诺 。

--soft意思是重置为中位 。

HEAD~HEAD^意思是移动以在 HEAD 之前承诺 。


替换上次承诺的新承诺 :

git commit --amend -m "message"

它将以新承诺取代最后一项承诺 。

与您一起工作的人源树树这会帮助你。

右单击右键在那日,选定 "重置( 当前分支)/ master 用于此承诺" 和上一个选定 “ 软” 重置.

Enter image description here

我发现这笔该网站描述如何撤销您在存储库中的承诺 。

一些命令 :

git commit --amend        # Change last commit
git reset HEAD~1 --soft   # Undo last commit