Sometimes you need to move your develop from a branch to another; in this case the cherry pick command is your friend.

Definition: given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).

Move a single commit

git checkout <your branch>
# cherry pick with automatic local commit
git cherry-pick <commit_hash>
# without automatic local commit
git cherry-pick <commit_hash> --no-commit

Log all commit from A branch to B branch

Usefult command to log all the commit actions between two branches

git log A..B > /yourlocation/filename.log

Move a range of commits

It means that you would like to apply multiple cherry pick from <commit_hash_from> to <commit_hash_to>

Considerations

  • if you would like to include also the modification made inside the <commit_hash_from> you have to start from previous one <commit_hash_from-1>
  • if in between your <commit_hash_from> and your <commit_hash_to> there is a merge, all that changes will be replicated. If this case is not match your requirements then you need to manually import each commit hash with cherry-pick starting from the oldest.
git checkout <your branch>
git cherry-pick <commit_hash_from>^..<commit_hash_to>

In case of conflict in one of the merge, resolve it locally, commit and then

git cherry-pick --continue

or if you mess up something go for

git cherry-pick --abort

Categories: Bash

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.