Jonathan
Jonathan

Reputation: 3534

Git rebase to older commit

After picking up a project on and off for the last year, I've managed to put myself in a bit of a git bind. Here's what happened:

  1. Starting Production version. We'll call this A

  2. Made some big feature changes that never got finished. Accidentally committed this to the master branch. Code never went into production. We'll call this commit B.

  3. A few months go by and I need to make some hotfixes on production. Used "git checkout A ." to revert to the A commit, make my hotfix changes then commit on the master branch over the top of B as C.

  4. Want to finish features from commit B. Use "git checkout B -b featureBranch" to get a new branch with all of my unfinished features from commit B. However, none of my hotfixes from C are included.

If I run a "git rebase master", all of my C commit fixes get applied but I lose my changes from commit B.

How do I bring forward my C commit changes without losing my B commits?

Upvotes: 2

Views: 2137

Answers (1)

VonC
VonC

Reputation: 1328642

The easiest way would be a cherry-pick (git cherry-pick):

git checkout featureBranch
git cherry-pick C

That will work if, later, featureBranch will simply replace the current master.

Upvotes: 3

Related Questions