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

git add myfile.txt

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


当前回答

如果你在初始承诺中,你不能使用git reset,只要声明“破产破产”并删除.git文件夹重新开始

其他回答

假设我创造了一个新的文件,newFile.txt:

Enter image description here

假设我无意中添加文件git add newFile.txt:

Enter image description here

现在我想撤销此添加, 在承诺之前,git reset newFile.txt:

Enter image description here

撤消撤消已经添加的文件使用 Git 很容易。 用于重设myfile.txt已经添加的,使用:

git reset HEAD myfile.txt

解释:

启动不需要的文件后,要撤消文件,您可以完成git reset. Head是在本地文件中您文件的头,而最后一个参数是您文件的名称。

我为你们创建了以下图像中的步骤, 更详细地介绍了这些步骤, 包括在这些情况下可能发生的所有步骤:

git reset HEAD file

请注意,如果您没有指定修改,则必须包含一个分隔符。例如,我的控制台:

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版总版)

键入 :

git status

Git会告诉你什么是舞台,等等, 包括关于如何解除舞台的指示:

use "git reset HEAD <file>..." to unstage

我发现吉特做的相当不错 裸体我做正确的事情 在这样的情况下。

注:最近Git版本(1.8.4.x)更改了此电文:

(use "git rm --cached <file>..." to unstage)

要撤销git add, 使用 :

git reset filename