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

前端 未结 1 546
刺人心
刺人心 2021-02-05 23:57

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

相关标签:
1条回答
  • 2021-02-06 00:10

    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
    
    0 讨论(0)
提交回复
热议问题