简体   繁体   English

从目录中删除所有 git 文件?

[英]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.我想复制它以发送,但不想包括所有 .git 目录及其下的文件。

Is there a way to remove all the git files instead of manually deleting all of them?有没有办法删除所有 git 文件而不是手动删除所有文件?

The .git folder is only stored in the root directory of the repo, not all the sub-directories like subversion. .git 文件夹仅存储在 repo 的根目录中,而不是像 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.如何在 Linux 中删除文件夹下的所有.git目录。

Run this find command, it will list all .git directories under the current folder:运行这个 find 命令,它将列出当前文件夹下的所有.git目录:

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.应该只有 3 或 4 个.git目录,因为 git 每个项目只有一个 .git 文件夹。 You can rm -rf yourpath each of the above by hand.您可以rm -rf yourpath上面的每一个。

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.

cd to the repository then然后cd到存储库

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.确保不要意外地将单个点、斜杠、星号或其他正则表达式通配符通过管道传递到 find 中,否则rm会很乐意将其删除。

You can use git-archive , for example:您可以使用git-archive ,例如:

git archive master | bzip2 > project.tar.bz2

Where master is the desired branch. master是所需的分支。

In case someone else stumbles onto this topic - here's a more "one size fits all" solution.万一其他人偶然发现了这个话题——这里有一个更“一刀切”的解决方案。

If you are using .git or .svn , you can use the --exclude-vcs option for tar.如果您使用的是.git.svn ,则可以使用--exclude-vcs选项作为 tar。 This will ignore many different files/folders required by different version control systems.这将忽略不同版本控制系统所需的许多不同文件/文件夹。

If you want to read more about it, check out: http://www.gnu.org/software/tar/manual/html_section/exclude.html如果您想了解更多信息,请查看: http ://www.gnu.org/software/tar/manual/html_section/exclude.html

ls | ls | xargs find 2>/dev/null | xargs 找到 2>/dev/null | egrep /\.git$ | egrep /\.git$ | xargs rm -rf 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.此命令(它只是一个命令)将递归删除目录中的 .git 目录(和文件)而不删除顶级 git 存储库,如果您想提交所有文件而不管理任何子模块,这很方便.

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

This command will do the same thing, but will also delete the .git folder from the top-level directory.这个命令会做同样的事情,但也会从顶级目录中删除 .git 文件夹。

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.与 SVN 或 CVS 等其他源代码控制系统不同,git 将其所有元数据存储在单个目录中,而不是项目的每个子目录中。 So just delete .git from the root (or use a script like git-export ) and you should be fine.因此,只需从根目录中删除.git (或使用git-export之类的脚本)就可以了。

sudo find -name.git -exec rm -fr {};须藤找到-name.git -exec rm -fr {};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM