Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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)?

like image 455
neverendingqs Avatar asked Dec 29 '15 17:12

neverendingqs


1 Answers

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.

like image 123
manojlds Avatar answered Sep 18 '22 11:09

manojlds