3

git add -p allows you to traverse through each modified file one at a time.

I would like a similar version; however, it needs to allow you to stage one file at a time. I want to be able to stage and provide the commit message as well.

Josh Mein
  • 28,107
  • 15
  • 76
  • 87
David
  • 4,235
  • 12
  • 44
  • 52

3 Answers3

5

I think you need the switch -o for example:

git commit -o file1
CharlesB
  • 86,532
  • 28
  • 194
  • 218
Andras Huszti
  • 51
  • 1
  • 2
  • Yes this is what OP wants, a single command to add and commit a file – idlethread May 15 '12 at 08:24
  • It is possible to list all files you want to commit too using this option. `git commit -o file1 file2 file3` is also permitted ...and this is neither limited to three files only. – Igbanam Mar 29 '13 at 18:13
  • Fun Fact: `git commit -o file1` bypasses `.gitignore`s. Security issue maybe? – Igbanam Mar 29 '13 at 18:21
3

So you want to do this?

git add <file1>
git commit [-m "message"]
git add <file2>
git commit [-m "message"]
...
Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • @David If you do this in git, the commits are local and can even be tweaked if necessary using `git rebase -i` before anyone else sees them, so there is no need to accomplish all of the above in a single command, if that's what you were worried about. If you really want to do it all in one command, I guess you could write a little script that iterates through the output of some form of `git status`, calling `git add` or `git add -p` on each of them, and then calling `git commit` (without `-m`) to let you specify the message in a text editor. – Tyler Mar 03 '11 at 18:45
0

Here's a quickie I use to bang through all the modified items from git status. We do a commit one at a time so I can add comments for each one.

for each_git_file in
`git status | egrep 'modified|new file' | awk -F: '{print $2}' | sed 's/[\W\.]*//'`;
 do
     git commit -o $each_git_file;
 done
Douglas
  • 379
  • 4
  • 16