.gitignore不能按预期工作 [英] .gitignore not working as intended

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

问题描述

.gitignore中有3件事:

I have 3 things in my .gitignore:

node_modules/
credentials.js
bitbucket-pipelines.yml

问题在于,每当我对credentials.js进行更改时,我仍然可以在打开Sourcetree时提交该文件.

The issue is that, whenever I make changes to credentials.js, I am still able to commit that file when I opened up my Sourcetree.

我该如何解决?

推荐答案

与名称"ignore"可能暗示的相反.仅当您使用git add文件时才引用.gitignore:换句话说,基于.gitignore,不会排除已经添加到存储库(的索引)的文件.

In contrast to what the name "ignore" might suggest. .gitignore is only consulted when you git add files: in other words a file already added to the (index of the) repository will not be excluded based on the .gitignore.

首先,最好修改.gitignore,以便不再添加文件.将以下行添加到.gitignore文件:

First you better modify the .gitignore such that the file is no longer added. Add the following line to the .gitignore file:

public/app/credentials.js

接下来,您需要从存储库中排除文件.可能您不想从文件系统中删除文件,可以使用以下方法完成:

Next you need to exclude the file from the repository. Probably you don't want to remove the file from your file system, this can be done with:

git rm --cached public/app/credentials.js

--cached标志可确保不会从文件系统中删除文件. (如果不重要,则可以使用git rm public/app/credentials.js,但这将删除该文件.)

The --cached flag ensures the file will not be removed from your file system. (If not important, you can use git rm public/app/credentials.js, but this will remove the file).

这篇关于.gitignore不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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