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
Celticist, Computer Scientist, Nerd, sometimes a poet…
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
--porcelainoption togit statusas that is guaranteed not to change between versions of gitAlso, it is unnecessary to use
grep x | awkas awk is designed to do the line filtering itself.So something along the lines of:
git status --porcelain | awk '/^.M/ {print substr($0,4)}' | xargs git addThe problem with this code is that it doesn’t handle the renamed form (X -> Y) of file names
git statusmight output. Also,xargsdoes correctly handle space-containing file names on my system, but I don’t know if that is universal.