Linux command to delete all files except .git folder?

后端 未结 6 652
别跟我提以往
别跟我提以往 2020-12-15 03:46

I want to delete all of the current directory\'s content except for the .git/ folder before I copy the new files into the branch.

6条回答
  •  星月不相逢
    2020-12-15 04:18

    One way is to use rm -rf *, which will delete all files from the folder except the dotfiles and dotfolders like .git. You can then delete the dotfiles and dotfolders one by one, so that you don't miss out on important dotfiles like .gitignore, .gitattributes later.

    Another approach would be to move your .git folder out of the directory and then going back and deleting all the contents of the folder and moving the .git folder back.

    mv .git/ ../
    cd ..
    rm -rf folder/*
    mv .git/ folder/
    cd folder
    

提交回复
热议问题