How to fix huge amount of commits after rebase

49 Views Asked by At

I had a fairly old branch and I tried to rebase it to master. I think I messed up really bad, can someone help me on how to fix it? Here is what I did:

  1. I used git rebase origin/master. VSCode showed that there are 4 commits to pull, and 25k to push
  2. I checked the status with git status. The feature branch commits were on top of the master commits.
  3. I pulled using git pull, and a merge commit got created on top of all others (saw that with git status afterwards)
  4. I pushed using git push --force-with-lease

Now the GitHub PR shows all those commits and thousands of changes, and I don't know how to fix it. In my previous company we only used git merge so this entire approach is very new to me.

Thank you!

2

There are 2 best solutions below

0
matt On

At the GitHub end, delete (close) the "bad" PR that you just made.

At your end, whip out the reflog and find the commit before the rebase. On your branch, reset --hard to that commit.

You have now undone everything described in your question.

5
FlushBG On

I managed to fix it. What I did:

  1. git reflog to identify what commit I was on. It was the one before rebase (start), and in my case - HEAD@{10}
  2. git reset --hard HEAD@{10}
  3. All the extra commits (25k in my case) got listed as difference from the remote branch, and VSCode was prompting me to pull them
  4. Instead, I used git push origin <branch-name> --force
  5. All is in sync in the local branch, and the PR shows only the 4 commits made by me