0

I have a config file which I don't want to store in my repo. Unfortunately I added it to repo by accident, but after few commits I removed it and added to .gitignore file. Only problem I have now is that when checking out a commit from times before ignoring this file, Git still modifies this file and removes it when going back to the current commit, so I lose it permanently. How can I fix it?

Karol Selak
  • 4,248
  • 6
  • 35
  • 65
  • 1
    Unfortunately, there's nothing you can do about the commits that have the file: they will always have the file. (Well, you can stop using them, and perhaps even "rewrite history" so that everyone stops using them, but that's a bit drastic.) You could try using sparse checkout to avoid touching that file but I have no experience with this, so am not making it an answer. – torek Nov 14 '17 at 18:11
  • Hm. I'm surprised this happens, since you usually get the "Untracked working tree file ... would be overwritten by merge" message, but having the file in .gitignore seems to suppress it. – trent Nov 14 '17 at 18:12
  • Actually I think https://stackoverflow.com/questions/3839152/prevent-git-checkout-from-overwriting-a-file is a more precise dupe. – trent Nov 14 '17 at 18:27

0 Answers0