Using git pull –rebase is a great way to avoid those awkward looking commits of Merge branch ‘development’ of in the list of commits. Very difficult to read the actual deltas. Performing a Git rebase helps solve this. However, from time-to-time I’ve received conflicts and could not figure out how to fix the rebase and carry on. Scariest moments of my life. Luckily I’ve been able to recover from this.
Git reflog to the rescue
Before performing the git pull –rebase you would have committed your code locally, so it is not lost.
When you’re in the awkward scenario of temp rebase branch, here are my steps of recovery:
- Check back out to the development branch
- Run git reflog
- Find your commit
- Copy the commit hash
- Run git reset –hard [commit id]
Replace [commit id] with your hash. - Before a regular git pull
This leaves you with the awkward Merge branch commit, but oh well. - Now push your code in git push
No code lost and you’re good to go.
As a funny aside I like to pronounce “reflog” as re flog instead of ref log. Probably because I just felt like I received a good flogging…