I'm a bit puzzled by a GIT situation.
I'm working on a GIT versioned project and I just noticed that some commits that we thought were already on the master branch weeks ago are actually missing. I remembered these commits were pushed by someone else on a feature branch “feature/something", which does not exist anymore.
I tried to find those missing commits to fix our mistake and to push them on a permanent branch. In this team, each developer puts the ID of the ticket he is working on in the commit message. So I know for sure ticket id (e.g 1234) is in the commit message I’m looking for, so I tried:
git log --all --grep=1234
git log -g --grep=1234
git log --all | grep 1234
git reflog | grep 1234
All of these commands returned nothing.
At this point, I was about to give up and then I remembered our git repo is integrated with Slack, so I searched 1234 in slack history and found the commits hashes. I immediately tried:
git show hash1
git show hash2
which surprisingly worked! It displayed all the commit information. So the commits are there, somehow still on my local repository. So I wanted to double check how I missed them:
git reflog | grep hash1
git branch --contains hash1
git fsck --lost-found | grep hash1
Nothing.
git fsck --unreachable | grep hash1
unreachable commit hash1
And here it is, in the unreachable commits list.
But this is a big project and git fsck --unreachable
returns a tons of commits, how could I have found this lost commit by keyword ?
If we did not have a third party tool logging the git activity, maybe I would have tried piping the output of git fsck back into git show somehow
and grepping on the result but that seems like a lot to do just to find a commit that I know is right here somewhere.
P.S: I’m sorry I can’t share the repo, it’s a private project but the following should reproduce the situation:
User A:
git clone <repo>
git checkout -b feature/something
# add something to commit
git commit -m “special-keyword"
git push origin feature/something
User B:
git clone <repo>
git push origin :feature/something
Now User B works for weeks, and then tries to find the commit "special-keyword" pushed by User A.