With Git, how do I commit a load of deleted files in one go?

前端 未结 2 1366
青春惊慌失措
青春惊慌失措 2021-01-16 20:58

I have a load of deleted files I want to commit.

But I don\'t want to type git rm for each one.

If i type git rm . -r it will try and delete everything.

相关标签:
2条回答
  • 2021-01-16 21:26
    git add -u
    

    Will stage all changes including deletions. This is usually the simplest way forward. You can restrict it to certain paths if this is more suitable.

    e.g.

    git add -u ProjectX
    

    After doing either you can use the path form of reset to 'unstage' any changes that you didn't want.

    git reset -- dontcommitme.txt
    

    To be absolutely sure that you are only staging deletions, you would have to do something like this:

    git diff --name-only --diff-filter=D | xargs git rm --
    

    Or if you have access to a GNU xargs and need to copy with whitespace in filenames:

    git diff -z --name-only --diff-filter=D | xargs -0 git rm --
    
    0 讨论(0)
  • 2021-01-16 21:40

    git commit -a

    should work as long as those are your only changes (it will add all unstaged files and commit).

    0 讨论(0)
提交回复
热议问题