我使用命令错误地将文件添加到 Git :
git add myfile.txt
我还没跑呢git commit
。我如何撤销这些修改,使这些修改不包含在承诺中?
我使用命令错误地将文件添加到 Git :
git add myfile.txt
我还没跑呢git commit
。我如何撤销这些修改,使这些修改不包含在承诺中?
当前回答
git add myfile.txt
# 这将将您的文件添加到待发列表中
与这个命令完全相反的是,
git reset HEAD myfile.txt # This will undo it.
因此,您将处于上一个状态。指定的状态将再次出现在未跟踪的列表中(先前的状态)。
它会用指定的文件重置你的头。 所以, 如果您的头没有它意味着, 它只会重置它 。
其他回答
我会用git restore --staged .
或git restore --staged <filename>
您也可以使用git rm --cached
然而,git rm
命令应最好用于已跟踪的文件 。
只是类型git reset
它将复返,犹如你从未打过字一样。git add .
自从你最后一次承诺之后,你一定要保证你以前的承诺。
键入 :
git status
Git会告诉你什么是舞台,等等, 包括关于如何解除舞台的指示:
use "git reset HEAD <file>..." to unstage
我发现吉特做的相当不错 裸体我做正确的事情 在这样的情况下。
注:最近Git版本(1.8.4.x)更改了此电文:
(use "git rm --cached <file>..." to unstage)
请注意,如果您没有指定修改,则必须包含一个分隔符。例如,我的控制台:
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 add -i
选择 选项 3 到 取消 添加文件 。 在我的情况中, 我通常要添加多个文件, 用交互模式, 您可以使用这样的数字来添加文件 。 这将除 4: 1, 1, 2, 3, 和 5 以外, 全部要用这个数字来添加文件 : 1, 2, 3 和 5
要选择一个序列, 只要类型 1-5 就可以从 1 到 5 全部取出 。