How to get back your git commits after somebody ate them


You do a git pull and you find that someone has undone all the changes you’ve made today. To restore your commits, you’ll need to create a branch, checkout your commit you want to restore, and merge your branch into master (or whatever branch you want to restore to).

git checkout -b newBranch
git checkout 459a100 .
git diff --name-only master
git add .
git status
git commit -m 'restore commits after funky merge'
git checkout master
git pull
git merge newBranch

Hopefully there will be no merge conflicts. If so, you’ll need to sort those out before you can push. Also, some people will tell you rebase instead. However, this works for me. YMMV.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments Protected by WP-SpamShield Spam Blocker