Notes

Convert commits to branches and bring back reverted changes with cherry-pick

Edit on GitHub

Git & Github

Scenario:

  • i have 3 old commits that were reverted and which i need to add back to code
  • i want all those commits to be in one (new) branch and pushed as one change (feature)
  • i don’t want the history or any commits that happened in between, i want ONLY the code that was changed inside that particular commit
  • (optional) squash all commits into one and push it to remote
 1# create a new branch, we use Gitflow
 2git flow feature start bringBackChange
 3# git checkout -b bringBackChange 
 4
 5# cherry pick a commit
 6git cherry-pick -x abc123 
 7
 8# pick multiple commits
 9git cherry-pick -x 456def ghi789
10
11# resolve conflicts and continue
12git cherry-pick --continue
13
14# bail out
15git cherry-pick --abort
  • -x will add a message saying that this commit was cherry pciked
(cherry picked from commit abc123)
  • --no-commit, bring the changes but don’t commit

NOTES:

  • you should merge if you can. Cherry picking creates duplicates of original commits..