This is a description of a bug I've discovered in git version 2.37.1
Imagine you have a folder where you worked on some files. Now you want to turn the folder into a git repo.
If you have files in a folder and then initiate-add-reset git commands you lose everything you had in the folder.
Run the following in your bash shell to see:
clear; \
[[ -d /tmp/evilgit ]] && rm -rdI /tmp/evilgit; \
mkdir /tmp/evilgit/; \
cd /tmp/evilgit/; \
echo "----------------- Create some files:"; \
pwd; \
echo -n "ls -l: "; \
touch a.txt b.txt c.txt; \
ls; \
echo "----------------- Now, init the repo:"; \
echo -n "git init: "; \
git init 2> /dev/null; \
echo "git add: a.txt b.txt c.txt"; \
git add ./*; \
echo -n "git reset --hard: "; \
git reset --hard; \
echo "\n----------------- Check files again:"; \
echo "ls -l: "; \
ls; \
echo "No files! " ; \
echo "\n----------------- Now, all the files we have created are gone!"; \
cd .. ; \
rm -rdI /tmp/evilgit
I had som side-project with snippets I've gathered over time. Then I decided to push my files into several repos and then I've initiated git repo and added these files for tracking, but I didn't commit them! Instead, I decided to --hard reset and everything was gone! No way to recover them! You can't use reflog or restore or anything!
Thankfully, I made few backups before that so files aren't lost. Imagine magnitude of the issue if that was some important project.
I've repoted the issue to the git@vger.kernel.org on August 7, 2022.
Sunday, August 7, 2022