Git – How to run git rebase interactive mode to remove duplicate commits

gitgit-interactive-rebasegit-rebase

I made a mistake when I rebase to a recent commit. ( I forgot to git fetch --all first, then rebase), and I've committed and pushed to the remote branch since. Now I did the rebase properly by fetching first, solved the conflicts, and pushed to the remote branch. Now, it seems all my recent commits are showing up twice. What I would like to do is to use git rebase interactive mode, pick all the commits that I want, then rebase properly to the commit sha code.

Is this the way to do this? and if I start git rebase -i, which sha code should I use, the original branching point sha code? or the most recent sha code?

Best Answer

Give git rebase the number of commits back in time. For 10 commit back in history:

git rebase -i HEAD~10

Then simply delete the lines for the commits you want to remove in the text editor that is shown. Saving the file and exiting will start the rebase and the lines that were removed will no longer be in the history once the rebase has completed.