gitignore提交后 [英] gitignore after commit
问题描述
我有一个托管在Github上的git仓库。在提交很多文件后,我意识到我需要创建 .gitignore
并排除 .exe
, .obj
文件。
然而,它会自动从存储库中删除这些提交的文件吗?有没有办法强制这样做?
不,你不能强制删除已经在repo中提交的文件因为它被添加到 .gitignore
您必须 git rm --cached
删除您不想在回购中使用的文件。 ( - 缓存,因为你可能想保留本地副本,但从回购中删除。)因此,如果你想从你的回购中删除所有的exe文件
git rm --cached /\*.exe
(注意星号*是从shell引用的 - 这让git,而不是shell,扩展了文件和子目录的路径名)
I have a git repository hosted on Github. After committing many files, I am realizing that I need to create .gitignore
and exclude .exe
, .obj
files.
However, will it automatically remove these committed files from the repository? Is there any way to force that?
No you cannot force a file that is already committed in the repo to be removed just because it is added to the .gitignore
You have to git rm --cached
to remove the files that you don't want in the repo. ( --cached since you probably want to keep the local copy but remove from the repo. ) So if you want to remove all the exe's from your repo do
git rm --cached /\*.exe
(Note that the asterisk * is quoted from the shell - this lets git, and not the shell, expand the pathnames of files and subdirectories)
这篇关于gitignore提交后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!