Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add only modified already staged files

Tags:

git

How do I re-add files that are staged, but then I modified after staging? I don't want to add them manually one by one.

$ 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:   file1
 modified:   file3

Here I don't want file3 to be staged.

like image 643
Antoine Bolvy Avatar asked Dec 06 '25 08:12

Antoine Bolvy


1 Answers

Turns out git update-index has an option just for that:

git update-index --again

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

Sources:

  • https://stacktoheap.com/blog/2016/01/02/git-add-only-files-already-staged/
  • https://git-scm.com/docs/git-update-index
like image 147
Antoine Bolvy Avatar answered Dec 08 '25 01:12

Antoine Bolvy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!