0

Just discovered a commit was made to the wrong branch, but not pushed to origin. That same branch has had a lot of commits after it that have been pushed (by another developer).

How do I bring over just that one un-pushed commit to another branch (or get rid of it altogether)? I know I can cherry pick it over to somewhere else, but what is the best way to delete it afterwards without deleting all of the changes after it?

Using Gitkraken, but whatever will get the job done.

user2521295
  • 823
  • 2
  • 12
  • 23

1 Answers1

0

First, cherry pick it to the proper branch.

git checkout the-proper-branch
git cherry-pick the-commit-id

Then go back to the wronged branch and remove it with an interactive rebase starting at the offending commit.

git checkout the-wronged-branch
git rebase -i the-commit-id~

This will pop up an editor with a line for each commit and instructions. Delete the line of the offending commit, save, quit, and the branch's history will be rewritten without the offending commit.

See Rewriting History in Pro Git for more.

Schwern
  • 153,029
  • 25
  • 195
  • 336