I often have a situation where I have git add
ed a set of files for a commit, but then have to make a modification to those files so end up with the modifications on those same files in Changed but not updated
.
Is there a one liner I can execute to git add
only the files that exist in Changed but not updated
and Changes to be committed
lists?
markdsievers$git status
# On branch master
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: src/com/foo/Bar.java
# modified: src/com/foo/Foo.java
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: src/com/foo/Bar.java
# modified: src/com/foo/Foo.java
# modified: src/com/foobar/FooBar.java
For the above example I only want Foo.java
and Bar.java
but not FooBar.java
added to the Changes to be committed:
list.
If unwanted files were added to the staging area but not yet committed, then a simple reset will do the job: $ git reset HEAD file # Or everything $ git reset HEAD . To only remove unstaged changes in the current working directory, use: git checkout -- .
The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.
This is one way:
git add -u $(git status --porcelain | grep ^MM | cut -d ' ' -f 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With