【问题标题】:.gitignore not working as intended.gitignore 没有按预期工作
【发布时间】:2018-07-05 11:01:39
【问题描述】:

我的 .gitignore 中有 3 样东西:

node_modules/
credentials.js
bitbucket-pipelines.yml

问题是,每当我对credentials.js 进行更改时,当我打开我的Sourcetree 时,我仍然能够提交该文件。

我该如何解决这个问题?

【问题讨论】:

  • 试试git rm --cached credentials.js
  • 为了解释上面的评论,如果你还没有删除credentials.js被存储库跟踪,那么它在.gitignore中的存在将不会做任何事情。

标签: git


【解决方案1】:

与“忽略”这个名字所暗示的相反。 .gitignore 仅在您使用 git add 文件时才被咨询:换句话说,不会根据 .gitignore 排除已添加到存储库(索引)的文件。

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

public/app/credentials.js

接下来,您需要从存储库中排除该文件。可能您不想从文件系统中删除文件,可以这样做:

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

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

【讨论】:

  • 如果下次我想编辑 credentials.js 并提交文件怎么办?
  • 然后你可以从.gitignore中删除credentials.js文件。然后添加文件并提交。
  • 你能试着回答这个问题stackoverflow.com/questions/51190478/… 吗?
猜你喜欢
  • 2021-10-19
  • 2020-03-18
  • 2012-06-14
  • 2014-11-15
  • 1970-01-01
  • 2012-07-02
  • 2011-09-07
  • 2013-03-03
  • 2015-05-18
相关资源
最近更新 更多