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

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


当前回答

“ 将工作树重置为最后一次承诺 ”

git reset --hard HEAD^ 

"清除工作树上的未知文件"

git clean    

见 -Git 快速参考

注:此命令将删除您上一个任务所以要谨慎使用!git reset --hard更安全。

其他回答

git reset --soft HEAD~1

git status

Output

在分母上
您的分行在“ 来源/ 主机” 前面 1 个承诺 。
(使用“ little push” 发布您的本地承诺)

拟承诺的修改:
(使用“ git reconful -- paged...” 到 unstage) 新文件 : file1

git log --oneline --graph

Output

  • 90f8bb1 (HEAD - > 主人) 第二次承诺\
  • 7083e29 初始仓库承诺

使用此命令 :

git checkout -b old-state number_commit

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

一些命令 :

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

认为我们有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

如果你有Git 外加已安装, 您可以运行git undo撤消最近的承诺。git undo 3将撤销最后三项承诺。