提交后的.gitignore [英] .gitignore after commit

查看:69
本文介绍了提交后的.gitignore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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?

推荐答案

否,您不能仅由于将其添加到.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆