git cherry-pick or merge specific directory from another branch

Here is the right way to cherry-pick commits from another branch for one folder:

git format-patch -k --stdout master...featureA -- tools/mytool | git am -3 -k

This will apply the patches to the “tools/mytool” files only, in order.

If you have a merge conflict on any commit, it will pause for you to fix it. git am --continue will resume where it left off.

See also Git documentation for:

  • git am
  • git format-patch

Leave a Comment