Simpler way to stage only modified files in Git (not deleted)

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
链接地址: http://www.djcxy.com/p/1216.html

上一篇: 在Rails中覆盖MIME类型

下一篇: 更简单的方式在Git中仅对已修改的文件进行分段(未删除)