Reputation: 4459
I have a git repo that has a directory full of user uploaded files. The directory also contains a .gitignore */
.
I did a pull from a remote repo and all of those files in the directory were deleted without warning.
What could have caused this to happen?
All of the research I have done tells me it is a deliberate action to delete all of those files and not possible to do by accident. Is that true or is there another git command that will silently delete all of those files?
Upvotes: 3
Views: 4848
Reputation: 60235
.gitignore is a convenience that keeps noise from showing up on status reports or being automatically added by git add .
and the like, that's all. You can explicitly add an ignored file and git will then care about that particular file anyway, and naming a file in .gitignore won't make git stop caring about an already-tracked file.
If git pull
deleted files, then those files were tracked and deleted. You can get them back by git checkout "@{may 21 17:30 pdt}"
or some such ref for your checked-out commit as of the pull.
It's remotely possible that someone added the files, didn't commit the changes, and forced the merge, making the orphans harder to find, but unless someone explicitly wiped git's memory git fsck --lost-found
is like the old undelete programs, it'll drop copies of everything you ever cared about but then discarded into .git/lost-found
.
git ls-files -ic --exclude-standard
will show you tracked files that match an ignore spec, i.e. files that somebody might have added or ignored by mistake. Come to think of it, that might not be a bad line for a pre-commit hook,
git ls-files -ic --exclude-standard \
| sed '${p;s,.*,*** '"$0"' refusing commit with tracked files marked as ignored in the standard excludes lists,;q1}'
Upvotes: 2