简体   繁体   English

提交后,如何 gitignore git 存储库中的所有单个文件扩展名文件?

[英]How do you gitignore all single file extension files from a git repository after committing?

I'm new to using git and was wondering how do I remove all cached .exe files from a git repository (I want to keep them in my working folder).我刚开始使用 git,想知道如何从 git 存储库中删除所有缓存的.exe文件(我想将它们保留在我的工作文件夹中)。 The root folder has subfolders that also have the .exe files.根文件夹包含也包含.exe文件的子文件夹。 Will the following command work or do I have to do something else?以下命令会起作用还是我必须做其他事情? I understand the -r is for removing directories and not files and it just seems wrong, and on searching about this topic, only relevant thing I found was using find and delete commands, but I'm not sure about how to use them.我知道 -r 用于删除目录而不是文件,它似乎是错误的,在搜索这个主题时,我发现唯一相关的事情是使用finddelete命令,但我不确定如何使用它们。

git rm --cached -r *.exe

Edit: I ran the command and it only removed the .exe from root folder not the sub folders Is manually listing all sub folder paths and running that command the only option?编辑:我运行了命令,它只从根文件夹中删除了 .exe 而不是子文件夹 手动列出所有子文件夹路径并运行该命令是唯一的选择吗?

Since passing the git command with it's cached flag is required, for people who are unfamiliar with chaining commands in linux/ unix, the recursive remove unix answer is not sufficient.由于需要传递带有缓存标志的 git 命令,对于不熟悉 linux/unix 中的链接命令的人来说,递归删除 unix 答案是不够的。

This should do it (in an sh compatible shell):这应该这样做(在sh兼容的 shell 中):

find . -name '*.exe' -exec git rm --cached '{}' \;

Alternatively, less elegant but easier to compose:或者,不那么优雅但更容易组合:

ls -R | grep '.exe$' | xargs git rm --cached

The trouble with your git rm -r command is that it will only recurse into directories whose name ends with .exe , which is obviously not what you want.您的git rm -r命令的问题在于它只会递归到名称以.exe结尾的目录中,这显然不是您想要的。

Escape the wildcard so Git sees it rather than your shell:转义通配符,让 Git 看到它而不是你的 shell:

git rm -n --cached \*.exe

(then rerun without the -n if you like what you see) (如果你喜欢你所看到的,然后在没有-n情况下重新运行)

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

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