tags:

views:

416

answers:

3

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
+6  A: 

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

...
Alex Reisner
+1  A: 
git add file01.txt
git stash
git commit -m'commit message'
git stash pop

repeat.

Charles Ma
I was going to down-vote this since there's no reason (from git's perspective) to do the stash. However, it's not a bad idea if you want to build and test between the stash and commit. That way you'll know that you're not committing broken code accidentally.
Pat Notz
What's wrong with committing broken code? As long as it's not published and nobody else manages to get hold of it.
Steve Folly
@Pat, I tend to do it out of habit of liking to have working commits and working with git svn where I have to stash changes before uploading changes with dcommit. But you're right, there is no reason in the OPs case to do the stash'n pop
Charles Ma
A: 

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.

daf