Bug with .gitignore and branch switching
- Date: Fri, 17 Mar 2017 16:42:35 -0400
- From: Nevada Sanchez <sanchez.nevada@xxxxxxxxx>
- Subject: Bug with .gitignore and branch switching
Here's an easy to reproduce bug. It's the only example I know of where
git legitimately loses data in a way that is unrecoverable,
unexpected, and without warning.
# git version 2.12.0
# Commit a file that will end up in .gitignore
echo 'original settings' > mine.conf
git add mine.conf
git commit -m "Unknowingly committed my settings."
echo '*.conf' > .gitignore
git add .gitignore
git commit -m "Users shouldn't commit their settings"
# Spin off a feature branch here (but don't check it out)
git branch feature
# Realize that we don't want that file committed
git rm mine.conf
git commit -m "Delete mine.conf"
echo 'Lots of laboriously tuned settings' > mine.conf
# Hop on the feature branch to do some work
git checkout feature
# Hmmm... My settings are gone
# original settings
# Lemme hop back
git checkout master
# Wait... they are gone for good!
# cat: mine.conf: No such file or directory