.gitignore 提交后 [英] .gitignore after commit
问题描述
我在 Github 上托管了一个 git 存储库.提交许多文件后,我意识到我需要创建 .gitignore
并排除 .exe
、.obj
文件.
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?
推荐答案
不,你不能仅仅因为一个已经在 repo 中提交的文件被添加到 .gitignore
No you cannot force a file that is already committed in the repo to be removed just because it is added to the .gitignore
你必须 git rm --cached
删除你不想要的文件.( --cached 因为您可能希望保留本地副本但从存储库中删除.)因此,如果您想从存储库中删除所有 exe,请执行
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
(注意星号 * 是从 shell 引用的 - 这让 git 而不是 shell 扩展文件和子目录的路径名)
(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屋!