我使用命令错误地将文件添加到 Git :
git add myfile.txt
我还没跑呢git commit
。我如何撤销这些修改,使这些修改不包含在承诺中?
我使用命令错误地将文件添加到 Git :
git add myfile.txt
我还没跑呢git commit
。我如何撤销这些修改,使这些修改不包含在承诺中?
当前回答
请注意,如果您没有指定修改,则必须包含一个分隔符。例如,我的控制台:
git reset <path_to_file>
fatal: ambiguous argument '<path_to_file>': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
git reset -- <path_to_file>
Unstaged changes after reset:
M <path_to_file>
(1.7.5.4版总版)
其他回答
在源树中,您可以通过 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 status
Git会告诉你什么是舞台,等等, 包括关于如何解除舞台的指示:
use "git reset HEAD <file>..." to unstage
我发现吉特做的相当不错 裸体我做正确的事情 在这样的情况下。
注:最近Git版本(1.8.4.x)更改了此电文:
(use "git rm --cached <file>..." to unstage)
也许Git已经进化了 自从你提出问题之后
$> git --version
git version 1.6.2.1
现在,你可以试试:
git reset HEAD .
这应该就是你要找的
如果你在初始承诺中,你不能使用git reset
,只要声明“破产破产”并删除.git
文件夹重新开始
git reset filename.txt
将会从当前索引“ 即将被执行” 区域中删除一个名为文件名. txt 的文件, 而不更改其它内容 。