情况:我有一个Git存储库,索引中已经有文件。我修改了几个文件,打开Git,用“Git add”把这些文件添加到我的暂存区。

问:如何从暂存区删除其中一个文件,但不从索引中删除它,或撤消对文件本身的更改?


当前回答

我的示例:

$ git status
On branch feature/wildfire/VNL-425-update-wrong-translation
Your branch and 'origin/feature/wildfire/VNL-425-update-wrong-translation' have diverged,
and have 4 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   ShopBack/Source/Date+Extension.swift
    modified:   ShopBack/Source/InboxData.swift
    modified:   ShopBack/en.lproj/Localizable.strings

你们可能注意到了

> Changes to be committed:
>       (use "git reset HEAD <file>..." to unstage)

其他回答

如果你想删除遵循某种模式的文件,并且你正在使用git rm——cached,你也可以使用file-glob模式。

在这里看到的。

当你执行git status时,git会告诉你如何取消运行:

Changes to be committed: (use "git reset HEAD <file>..." to unstage).

所以git重置HEAD <文件>为我工作,这些变化没有被触及。

您需要在文件的目录中,然后在终端中输入以下内容

git checkout -- <file>

Git重置<文件>

无论您是否有任何以前的提交。

您需要在文件的目录中,然后在终端中输入以下内容

git reset HEAD .

假设您只需要重置一个文件。