简体   繁体   English

停止跟踪对文件的更改

[英]Stop tracking changes to a file

I have a file "src/data/sensitive-data.json" that contains contents:我有一个包含内容的文件“src/data/sensitive-data.json”:

{
  "appInstanceKey": "<Virtual App Key Here>",
  "email": "<Email Here>",
  "password": "<Password Here>"
}

I pushed that to my repo.我把它推到了我的仓库。

I now added to my .gitignore我现在添加到我的 .gitignore

src/data/sensitive-data.json

and then pushed that to my repo in a separate commit.然后在单独的提交中将其推送到我的仓库。

I want to now change my sensitive-data.json to actual credentials so i make the change and tell git to stop tracking with SourceTree (i believe it's using git rm -r --cached) and push that.我现在想将我的敏感数据.json 更改为实际凭据,以便我进行更改并告诉 git 停止使用 SourceTree 进行跟踪(我相信它正在使用 git rm -r --cached)并推送它。

The problem is when someone new pulls the repo, the data folder and the sensitive-data.json file don't exist at all.问题是当有人拉取 repo 时,data 文件夹和sensitive-data.json 文件根本不存在。 I want it to exist with the original contents, but I want to be able to change the data locally without it being tracked.我希望它与原始内容一起存在,但我希望能够在本地更改数据而不对其进行跟踪。

What step did I mess up or what am I missing to accomplish this?我搞砸了什么步骤或者我错过了什么来完成这个? I looked at other SO answers and I feel like i'm following them correctly.我查看了其他 SO 答案,我觉得我正在正确地关注它们。

Thank you谢谢

There is a great article on github about removing sensitive data from repository, but maybe you should consider having structure like this: github上有一篇很棒的文章关于从存储库中删除敏感数据,但也许您应该考虑使用这样的结构:

/src/data/sensitive-data.json           <-- This is not tracked by git at all
/src/data/sensitive-data.json.example   <-- This is tracked by git

Having structure like that ensures that future code users will know how the file should be looking and it is pretty safe for you to not include sensitive data in your repository.拥有这样的结构可确保未来的代码用户知道文件的外观,并且在存储库中不包含敏感数据是非常安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM