简体   繁体   中英

Stop tracking changes to a file

I have a file "src/data/sensitive-data.json" that contains contents:

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

I pushed that to my repo.

I now added to my .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.

The problem is when someone new pulls the repo, the data folder and the sensitive-data.json file don't exist at all. 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.

Thank you

There is a great article on github about removing sensitive data from repository, but maybe you should consider having structure like this:

/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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