Search code examples
gitgit-mergegit-rebasegit-cherry-pick

Git - Merge a part of branch commits


How could I merge several, selected commits from branch B into A. I did this but I am not sure if there is a one line solution for this:

git log -p -1 B~~ | git apply
git log -p -1 B~ | git apply
git commit -m 'Merge penultimate and before penultimate B commits into A'

Solution

  • Use git cherry-pick

    In your case (when branch A is your current HEAD):

    git cherry-pick B~1