Remove all git files from a directory?

前端 未结 7 1663
不思量自难忘°
不思量自难忘° 2021-01-30 12:17

I have a folder under version control. I want to make a copy of it to send around, but don\'t want to include all the .git directories and the files underneath it.

Is

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 13:00

    How to remove all .git directories under a folder in Linux.

    Run this find command, it will list all .git directories under the current folder:

    find . -type d -name ".git" \
    && find . -name ".gitignore" \
    && find . -name ".gitmodules"
    

    Prints:

    ./.git
    ./.gitmodules
    ./foobar/.git
    ./footbar2/.git
    ./footbar2/.gitignore
    

    There should only be like 3 or 4 .git directories because git only has one .git folder for every project. You can rm -rf yourpath each of the above by hand.

    If you feel like removing them all in one command and living dangerously:

    //Retrieve all the files named ".git" and pump them into 'rm -rf'
    //WARNING if you don't understand why/how this command works, DO NOT run it!
    
    ( find . -type d -name ".git" \
      && find . -name ".gitignore" \
      && find . -name ".gitmodules" ) | xargs rm -rf
    
    //WARNING, if you accidentally pipe a `.` or `/` or other wildcard
    //into xargs rm -rf, then the next question you will have is: "why is
    //the bash ls command not found?  Requiring an OS reinstall.
    

提交回复
热议问题