I have a bunch of deleted files in my working branch that I'm not sure I want to commit yet. I need to commit my modified files as needed though.
This is what I came up with:
git add `git status | grep modified | cut -f2 | cut -f4 -d' '`
This answer does something similar but isn't much better: https://stackoverflow.com/a/8277826
So is there a simpler solution?
Just use git add --no-all .
(Git v. 2.0+) or git add .
(Git v. 1.x). This will pick up any files it can find by traversing the current directory, which naturally won't include deleted files.
Of course, this also picks up any untracked files too. If you need to avoid those, then you can use a more complicated expression. It's similar to yours, but it uses the output that's intended for scripting (so it's more stable and easier to parse):
git diff-files -z --diff-filter=M --name-only --relative | xargs -0 git add
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