Remove all git files from a directory?

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 there a way to remove all the git files instead of manually deleting all of them?


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.


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

This find command 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 do those 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 `/` to xargs rm -rf, 
//then everything will be gone.  Which requires an OS reinstall.

You can use git-archive, for example:

git archive master | bzip2 > project.tar.bz2

Where master is the desired branch.

链接地址: http://www.djcxy.com/p/26270.html

上一篇: cp命令应该忽略一些文件

下一篇: 从目录中删除所有的git文件?