我正在尝试使用.gitignore
文件排除文件夹templates.js
中的public/app/
文件。我的.gitignore
文件如下所示:
/vendor
/node_modules
composer.phar
composer.lock
.DS_Store
templates.js
但是当我签入Git Gui时,templates.js
文件仍然显示在其中。如何使用专门排除文件.gitignore
?
与名称“ ignore”可能暗示的相反。.gitignore
仅在您git add
归档时进行咨询:换句话说,基于不会排除已经添加到(存储)索引的文件.gitignore
。
首先,您最好修改,.gitignore
以便不再添加文件。将以下行添加到.gitignore
文件中:
public/app/template.js
接下来,您需要从存储库中排除文件。可能您不想从文件系统中删除文件,可以通过以下方法完成:
git rm --cached public/app/template.js
该--cached
标志确保文件不会从文件系统中删除。(如果不重要,则可以使用git rm public/app/template.js
,但这将删除该文件)。
之所以.gitignore
不积极使用,是因为有时您可能想覆盖.gitignore
。假设您不想跟踪*.log
文件,可以*.log
在中指定.gitignore
。但是,如果要跟踪一个特定的对象,则可以添加git add -f some.log
。该-f
标志强制git
添加文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句