Remove all git files from a directory?

前端 未结 7 1631
不思量自难忘°
不思量自难忘° 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条回答
  • 2021-01-30 12:54

    ls | xargs find 2>/dev/null | egrep /\.git$ | xargs rm -rf

    This command (and it is just one command) will recursively remove .git directories (and files) that are in a directory without deleting the top-level git repo, which is handy if you want to commit all of your files without managing any submodules.

    find 2>/dev/null | egrep /\.git$ | xargs rm -rf

    This command will do the same thing, but will also delete the .git folder from the top-level directory.

    0 讨论(0)
  • 2021-01-30 12:56

    The .git folder is only stored in the root directory of the repo, not all the sub-directories like subversion. You should be able to just delete that one folder, unless you are using Submodules...then they will have one too.

    0 讨论(0)
  • 2021-01-30 12:59

    cd to the repository then

    find . -name ".git*" -exec rm -R {} \;
    

    Make sure not to accidentally pipe a single dot, slash, asterisk, or other regex wildcard into find, or else rm will happily delete it.

    0 讨论(0)
  • 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.
    
    0 讨论(0)
  • 2021-01-30 13:06

    You can use git-archive, for example:

    git archive master | bzip2 > project.tar.bz2
    

    Where master is the desired branch.

    0 讨论(0)
  • 2021-01-30 13:07

    Unlike other source control systems like SVN or CVS, git stores all of its metadata in a single directory, rather than in every subdirectory of the project. So just delete .git from the root (or use a script like git-export) and you should be fine.

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