Skip to content

Instantly share code, notes, and snippets.

@dmpv
Last active December 14, 2016 17:56
Show Gist options
  • Save dmpv/b85f42485b33bb77498f1e6433f35939 to your computer and use it in GitHub Desktop.
Save dmpv/b85f42485b33bb77498f1e6433f35939 to your computer and use it in GitHub Desktop.
Git Cases

Pick the range of commits (from A to B inclusive) from source branch and apply to destination branch

  • cherry-pick

    • git cherry-pick A~..B or
    • git cherry-pick A^..B (NB: Use A\\^ when using Oh-My-ZSH)
  • rebase
    0. Checkout a new temporary branch at the current location
    git checkout -b tmp
    0. Move the destination branch to the head of the new patchset
    git branch -f integration last_SHA-1_of_source_branch_range
    0. Rebase the patchset onto tmp, the old location of destination branch
    git rebase --onto tmp first_SHA-1_of_source_branch_range~1 destination

  1. The Ultimate Time Machine: git reflog & gif reset HEAD@{N} --hard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment