1

I confused the remote url's for two different repos. The two repos correspond to a frontend and a backend application. I set the backend's remote-url to point to the frontend repo, and I didn't notice. I did a git pull, Git complained about unrelated histories so I kept pushing through and ran git pull --allow-unrelated histories fixed the "merge conflicts" and pushed the changes to the central repo. After viewing frontend code in the backend repo I slowly realized my blunder. So I tried to revert the changes but the backend repo has the frontend's git history baked into it so I keep seeing the frontend code files in the backend repo. Here is what the backend's repo git history graph looks like at the moment:I need to reset the repo to only include the right hand side of the history. The left hand side is the frontend's history line

How do I undo this??? I need to keep the history from commit e3282c79 down to e6ddfacc, and only this because it corresponds to the backend's git history. The left most line corresponds to the frontend's git history, and I don't need it.

I ran git revert to a commit previous the mixup but the git history still remained the same.

  • 2
    The fact that it was a `pull` rather than a `merge`, and that it involved the `--unrelated-histories` flag doesn't actually make a difference to what you need to do now, which is **not** a revert, it is to **re-point the branch**, discarding your merge commit and anything after it. – IMSoP Nov 10 '22 at 17:54
  • @IMSoP Thanks for this insight. Would you mind sharing how I can go about re-pointing the branch? – GeraCamoDev Nov 10 '22 at 18:48
  • 1
    checkout the branch and do `git reset --hard $sha`, or do `git branch -f ${branch} ${new_tip_commit}` or use `git update-ref`. Whichever you choose, make sure you understand what it does before you execute it. – William Pursell Nov 10 '22 at 19:01
  • @GeraCamoDev Look at the duplicate I pointed you to in my first comment. – IMSoP Nov 10 '22 at 20:50
  • Thanks! After doing a git reset --hard to the commit I wanted, I then did git push -f to fix the remote branch as well. Awesome! Thanks everyone! – GeraCamoDev Nov 10 '22 at 22:33

0 Answers0