Skip to content

Instantly share code, notes, and snippets.

@squio
Last active October 23, 2024 07:24
Show Gist options
  • Save squio/2e1d9b8e56be3a2162d9904e44e6676b to your computer and use it in GitHub Desktop.
Save squio/2e1d9b8e56be3a2162d9904e44e6676b to your computer and use it in GitHub Desktop.
HOWTO git: cherry-pick from merged commits

If you need to cherry pick merge commits

First switch to the branch you merged into (likely develop), then

git log --since=2024-10-01 --reverse --merges \
  --author="$(git config --get user.name)" >merges.txt

Now switch to the target branch you want to merge into (maybe release-20240501 or so)

Finally go through file merges.txt top down, and for every commit hash you want to cherry-pick:

git cherry-pick [commit-hash] -m 1 

Done!

MORE...

  • if you get unexpected merge conflicts which make no sense, the cherry-picked commit is likely already merged into the target branch; git cherry-pick --abort
  • if you want inspect the changes of a certain commit, use git diff <hash>~ <hash>
  • if you want to see if the commit is already included in the active branch: git branch $(git symbolic-ref --short HEAD) --contains <hash>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment