0

Let's say there is are a few gerrits with dependencies :

A <- B <- C

(C depends on B and B depends on A)

If I simply cherry-pick C, it will not work because the dependencies (A and B) will not be cherry-picked.

How can I easily cherry-pick C such that in my local tree, all its dependencies will be applied automatically in one command ?

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
Fuad
  • 1,419
  • 1
  • 16
  • 31

1 Answers1

1

If all of A, B and C have been submitted, you can consider git merge:

git merge C --no-ff
# merge commit does not invoke the hook commit-msg, so
# if your Gerrit requires Change-Id and you want to push
# the merged commits for review, use amend-commit to generate it
git commit --amend

If at least one of them has not been submitted, use git cherry-pick instead:

git cherry-pick HEAD..C --no-merges

HEAD..C is equivalent to all the commits reachable from C and new to the current branch. --no-merges excludes the merge commits among them. In an ideal case, merge commits don't involve conflicts and you don't need to cherry-pick them. If you do want to cherry-pick a merge commit, it's a bit annoying as you have to specify which parent to be the mainline.

If C and its ancestors are not available in the local yet, you need to fetch them first:

git fetch origin <refspec_of_C>

You can find the refspec of C on C's page. It's a ref like refs/changes/xx/xxxxx/x. If C has been submitted to a branch, you can fetch the branch instead.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53