0

I wanted to stop tracking a file, so I added it to .gitignore and did git rm --cache thefile.php to try to accomplish that. All seemed well. The file remained, but was no longer tracked. I pushed to Github.

Now another machine with the repo has pulled from Github and seen this:

root@server [/home/butkus/public_html]# git pull
Password for 'https://billybutkus@github.com':
Updating 42e1727..2e0aef4
Fast-forward
 .../path/to/file.php    | 13 -------------
 1 file changed, 13 deletions(-)
 delete mode 100644 path/to/file.php
root@server [/home/butkus/public_html]#

File is now actually deleted rather than just ignored. What did I do wrong?

This amazingly well upvoted answer tells me I did it exactly right: https://stackoverflow.com/a/1143800/631764

But I sure didn't.

Community
  • 1
  • 1
Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120

1 Answers1

2

You did it right. There is no way around the fact that other users will receive it as a deletion; they can restore the file by doing git checkout <commit> <filename>, where "commit" is the commit that last had the file.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • I am just surprised that git would do *anything* to a file that is in `.gitignore`. That just doesn't make any sense! – Buttle Butkus Feb 04 '16 at 01:28
  • @ButtleButkus: git treats ignored files as "not required, may destroy at any time". There is currently no way to tell git that some file is precious, but not version-controlled. – torek Feb 04 '16 at 02:11
  • Ok, so I check out that file and now it is in the list of files to be committed. But I don't want to commit it. Should I just remove it from cache again? – Buttle Butkus Feb 04 '16 at 06:31
  • Yes, or you can do `git reset head `. BTW, one gotcha is that if anyone checks out a branch/commit that has that file, their local copy will get overwritten with that file, with no warnings from git. Then when they checkout a commit where the file has been removed from source control, their local copy will be removed. – David Deutsch Feb 04 '16 at 11:38