Fun with Git
So, git has the —all command, which adds all tracked and untracked files for staging to commit. I really dislike this because I wanted something that would just add all the tracked files for staging to commit. So, a friend of mine in the office said that he had a shell script which did it so I give you git add for only tracked files:
git status | grep "modified: " | awk '{print $3}' | xargs git add
Does “git add -u” do what you need?
“git commit -a” does not add new files too
Yes, it does. I must have missed it when I was looking at the man file. Thanks!
Caveat emptor, that shell snippet doesn’t look like it’ll work with paths that contain spaces.
It would probably make more sense to use the
--porcelain
option togit status
as that is guaranteed not to change between versions of gitAlso, it is unnecessary to use
grep x | awk
as awk is designed to do the line filtering itself.So something along the lines of:
The problem with this code is that it doesn’t handle the renamed form (X -> Y) of file names
git status
might output. Also,xargs
does correctly handle space-containing file names on my system, but I don’t know if that is universal.