Doug Blogs

Git Back to the Future

May 01, 2015

Problem

I incorrectly merged the code I pulled from the upstream group project repository. I commited the merge to my local repo and pushed it to my fork of the project on my github.

Goals

  1. Reset my local repo back to the commit I want
  2. Redo the merge
  3. Push new merge commit up my fork of the project on github so I can later make a pull request on the group project repo

Solution

  1. git log “find the <sha> of the commit I want”
  2. git reset —hard <sha> “change my local repo to the version of the commit i want”
  3. git push “trigger merge. do the merge correctly”
  4. git add “adds merged file to commit”
  5. git commit “commits code to local repo”
  6. git push —force origin master “forces my local commits to override what is commited in my github fork of the project”

After all those steps, I checked my github fork of the project to see that my fixed merge was there and that I could make a pull request on the group project repo without a merge conflict.


Doug Kong

Written by Doug Kong. You should follow him on Twitter