Example:
» git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    modified:   a
    modified:   b
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:   a
If I have modified a file named a, and add parts of it to index, and there is a file named b  also in index.
I want to commit only file a in index, neither include b nor a in work directory.
The way I use is to use git commit -p and enter n to not stage. or git commit -p file and choose the part I want.
But if the part in file a already add in index, is there a better way to direct commit file a only in index part?
Supplement:
I think maybe that is wrong use of git.
Only the changes to be commited in the next commit, should add in the index.
Obvious the file b is not prepared to be commited, so it thould in the working directory.
git commit a would commit only a and leave b staged.
Here's an example from the man page :
$ edit hello.c hello.h
$ git add hello.c hello.h
$ edit Makefile
$ git commit Makefile
This makes a commit that records the modification to Makefile. The changes staged for hello.c and hello.h are not included in the resulting commit. However, their changes are not lost — they are still staged and merely held back.
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