I was doing a rebase when some commit had conflicts. During resolving the conflicts I accidentally added all of my untracked files. Because I too don't keep track of untracked files I could not remember which files to unstage. Or which files where staged as part of the conflicting commit.
Instead of figuring it out, I decided to git rebase --abort hoping to just start over. However, those files that were mistakenly added have now disappeared.
I would like to understand what had happened. And why git rebase --abort does not restore my working tree to its original state. And if possible, where to find these files. Some of them have valuable work.
Nothing has been lost!
The Git reflog records all commits made on local branches ("references" or "refs" for short) and also for all commits that
HEADpointed to.Run
git reflogand you should see all commits made during your aborted rebase process. The reflog should contain an entry "rebase (abort): returning to ...".Use
git logorgitkto inspect this commit (or any other commit of the reflog) and thengit branch hash-of-that-committo create a new branch pointing to that commit. You can then switch to that branch to extract the files.As to why the files were removed when aborting the rebase: Git only leaves untracked files alone during its operations. Once you tracked these files (intentionally or not), they became managed by Git. Switching branches or checking out different commits will remove (tracked) files from your working tree which are part of the "previous" commit but not part of the to-be-checked-out commit.
The good thing is that Git doesn't easily lose data that has been committed once.
If files never were committed, but the content of the file was staged (with
git add), then it is still possible to recover the content, but it is a bit more work. Rungit fsckto find any dangling blobs and then usegit cat-file -porgit showwith the object id of the respective blob. Once you have found the correct blob(s), redirect the output ofcat-file/showto a file with the desired name. Repeat for all your files.