Say there are several files modified and I just want one files committed each time. How to do that? Given an example with status looks like below. Thanks!!
Ex:
> git status
# modified: file01.txt
# modified: file02.txt
# modified: file03.txt
# modified: file04.txt
# modified: file05.txt
Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.
Save the file or files. Add only one file, or one part of the changed file: git add README.md. Commit the first set of changes: git commit -m "update the README to include links to contributing guide" Add another file, or another part of the changed file: git add CONTRIBUTING.md.
Use git add -p
followed by git commit
. git add -p
asks you for each change whether to stage it for committing, which is super convenient.
You can also use -p
with git reset
and git checkout
.
There are a few ways, but the simplest is probably:
git commit file01.txt
git commit file02.txt
...
Any paths you list after the commit command will be committed regardless of whether they're staged to be committed. Alternatively, you can stage each one, and then commit:
git add file01.txt
git commit
git add file02.txt
git commit
...
git add -p
described by daf's answer is nice, but for a more direct approach to picking and choosing, I'm really liking:
git add -e
It generates the appropriate patch, then loads it up in your preferred editor so that you can edit it as desired. When you save the file and exit the editor, and only the changes made by your edited version of the patch are added to the index.
If you accidentally close the editor without making changes, you'll probably want to use get reset HEAD
and then start over.
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