neverendingqs
neverendingqs

Reputation: 4276

Is it possible in Git to only stage files that are staged and modified?

Is it possible in Git to only stage files that have already been staged, but have been modified since?

For example, given:

> 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

Is it possible to tell Git to only stage file2 without specifying file2 (e.g. not git add file2 or something similar)?

Upvotes: 7

Views: 106

Answers (1)

manojlds
manojlds

Reputation: 301037

Looking beyond git add, you can do:

git update-index --again

From the docs:

Runs git update-index itself on the paths whose index entries are different from those from the HEAD commit.

which, as it turns out, is exactly what we need here.

Upvotes: 7

Related Questions