Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created March 30, 2016 16:29
Show Gist options
  • Save cheeyeo/d15c31cb0647610d31e30b35db6ad34a to your computer and use it in GitHub Desktop.
Save cheeyeo/d15c31cb0647610d31e30b35db6ad34a to your computer and use it in GitHub Desktop.
Using git cherry-pick and rebase

If only cherry picking the odd commit can do so directly using following:

git checkout master

git cherry-pick 62ecb3

The new commit 62ecb3 is applied to the master branch as a new commit through merge. Any conflicts has to be resolved.

For a range of commits, rebase is a better option.

Say we have two commits from a feature branch, 76cada and 62ecb3 and 62ecb3 is the head.

  • Create a new branch from feature branch up until the last commit we want,
git checkout -b newbranch 62ecb3
  • Then we rebase newbranch onto master:
git rebase --onto master 76cada^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment