我使用命令错误地将文件添加到 Git :

git add myfile.txt

我还没跑呢git commit。我如何撤销这些修改,使这些修改不包含在承诺中?


当前回答

在源树中,您可以通过 GUI 轻松地做到这一点。您可以检查源树命令用什么来取消文件 。

我创建了一个新的文件, 并将其添加到 Git 中。 然后我用“ 原始树 GUI” 解除了它。 这是结果 :

解除文件 [08/12/ 15 10: 43] git - c diff. mnemonicprefix= false - c c c核心. cootepath= false - creedical. helper= 源树重新设置 -q - 路径/ 到/ 文件/ files/ filename.java

源树用途reset以卸载新文件。

其他回答

使用使用git add -i以删除您即将承诺的添加文件 。 例如 :

添加您不想添加的文件 :

$ git add foo
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   foo
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
# [...]#

进入交互式添加以取消您的添加( 这里输入的 git 命令是“ r”( revert) , “ 1”( 列表返回显示的第一个条目) , “ return” 退出返回模式, 以及“ q” ( quit) :

$ git add -i
           staged     unstaged path
  1:        +1/-0      nothing foo

*** Commands ***
  1: [s]tatus     2: [u]pdate     3: [r]evert     4: [a]dd untracked
  5: [p]atch      6: [d]iff       7: [q]uit       8: [h]elp
What now> r
           staged     unstaged path
  1:        +1/-0      nothing [f]oo
Revert>> 1
           staged     unstaged path
* 1:        +1/-0      nothing [f]oo
Revert>> 
note: foo is untracked now.
reverted one path

*** Commands ***
  1: [s]tatus     2: [u]pdate     3: [r]evert     4: [a]dd untracked
  5: [p]atch      6: [d]iff       7: [q]uit       8: [h]elp
What now> q
Bye.
$

这就是你的证据 证明"foo"又回到了未追踪的名单上

$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
# [...]
#       foo
nothing added to commit but untracked files present (use "git add" to track)
$

在源树中,您可以通过 GUI 轻松地做到这一点。您可以检查源树命令用什么来取消文件 。

我创建了一个新的文件, 并将其添加到 Git 中。 然后我用“ 原始树 GUI” 解除了它。 这是结果 :

解除文件 [08/12/ 15 10: 43] git - c diff. mnemonicprefix= false - c c c核心. cootepath= false - creedical. helper= 源树重新设置 -q - 路径/ 到/ 文件/ files/ filename.java

源树用途reset以卸载新文件。

最直觉的解决方案之一是使用原始树.

您可以从舞台和非舞台拖放文件或拖放文件

Enter image description here

只是类型git reset它将复返,犹如你从未打过字一样。git add .自从你最后一次承诺之后,你一定要保证你以前的承诺。

git rm --cached . -r

将“ un- add- add” 添加您从当前目录中添加的所有内容递归到当前目录