[英]Remove all git files from a directory?
我有一个受版本控制的文件夹。 我想复制它以发送,但不想包括所有 .git 目录及其下的文件。
有没有办法删除所有 git 文件而不是手动删除所有文件?
.git 文件夹仅存储在 repo 的根目录中,而不是像 subversion 那样的所有子目录。 您应该可以只删除一个文件夹,除非您使用的是子模块......然后他们也会有一个。
如何在 Linux 中删除文件夹下的所有.git
目录。
运行这个 find 命令,它将列出当前文件夹下的所有.git
目录:
find . -type d -name ".git" \
&& find . -name ".gitignore" \
&& find . -name ".gitmodules"
印刷:
./.git
./.gitmodules
./foobar/.git
./footbar2/.git
./footbar2/.gitignore
应该只有 3 或 4 个.git
目录,因为 git 每个项目只有一个 .git 文件夹。 您可以rm -rf yourpath
上面的每一个。
如果您想在一个命令中将它们全部删除并过着危险的生活:
//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
到存储库
find . -name ".git*" -exec rm -R {} \;
确保不要意外地将单个点、斜杠、星号或其他正则表达式通配符通过管道传递到 find 中,否则rm
会很乐意将其删除。
万一其他人偶然发现了这个话题——这里有一个更“一刀切”的解决方案。
如果您使用的是.git
或.svn
,则可以使用--exclude-vcs
选项作为 tar。 这将忽略不同版本控制系统所需的许多不同文件/文件夹。
如果您想了解更多信息,请查看: http ://www.gnu.org/software/tar/manual/html_section/exclude.html
ls | xargs 找到 2>/dev/null | egrep /\.git$ | xargs rm -rf
此命令(它只是一个命令)将递归删除目录中的 .git 目录(和文件)而不删除顶级 git 存储库,如果您想提交所有文件而不管理任何子模块,这很方便.
查找 2>/dev/null | egrep /\.git$ | xargs rm -rf
这个命令会做同样的事情,但也会从顶级目录中删除 .git 文件夹。
与 SVN 或 CVS 等其他源代码控制系统不同,git 将其所有元数据存储在单个目录中,而不是项目的每个子目录中。 因此,只需从根目录中删除.git
(或使用git-export之类的脚本)就可以了。
使用 PowerShell
Get-ChildItem -Path .\path\to\folder -Filter ".git" -Recurse -Attributes "H" | Remove-Item -Force
更多解释:
须藤找到-name.git -exec rm -fr {};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.