在Git中,是否可能仅将已暂存且修改的文件添加到暂存区?

7

在Git中,是否有可能仅提交已经被暂存但自上次提交以来发生过修改的文件?

例如,给定以下情况:

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

        modified:   file1
        modified:   file2

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   file2
        modified:   file3

能否仅使用 Git 暂存 file2 而无需指定 file2(例如不使用 git add file2 或类似的命令)?
1个回答

7

除了git add之外,您还可以执行以下操作:

git update-index --again

从文档中得知:

对那些与 HEAD 提交不同的索引条目所在的路径运行 git update-index 命令。

而这正是我们需要的。


2
完美。另一个别名为:restage = update-index --again - neverendingqs
@neverendingqs - 是的,那很有用 :) - manojlds

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接