From 917f9e516e84f13cdc6dcdef2cf5153a77ac62e5 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 2 May 2025 23:14:16 -0500 Subject: [PATCH] Add Cherry Pick Multiple Commits At Once as a git TIL --- README.md | 3 +- git/cherry-pick-multiple-commits-at-once.md | 35 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 git/cherry-pick-multiple-commits-at-once.md diff --git a/README.md b/README.md index 25f13a2..e2f23fa 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1642 TILs and counting..._ +_1643 TILs and counting..._ See some of the other learning resources I work on: - [Get Started with Vimium](https://egghead.io/courses/get-started-with-vimium~3t5f7) @@ -317,6 +317,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Checkout Old Version Of A File](git/checkout-old-version-of-a-file.md) - [Checkout Previous Branch](git/checkout-previous-branch.md) - [Cherry Pick A Range Of Commits](git/cherry-pick-a-range-of-commits.md) +- [Cherry Pick Multiple Commits At Once](git/cherry-pick-multiple-commits-at-once.md) - [Clean Out All Local Branches](git/clean-out-all-local-branches.md) - [Clean Out Working Copy With Patched Restore](git/clean-out-working-copy-with-patched-restore.md) - [Clean Up Old Remote Tracking References](git/clean-up-old-remote-tracking-references.md) diff --git a/git/cherry-pick-multiple-commits-at-once.md b/git/cherry-pick-multiple-commits-at-once.md new file mode 100644 index 0000000..2dc8baf --- /dev/null +++ b/git/cherry-pick-multiple-commits-at-once.md @@ -0,0 +1,35 @@ +# Cherry Pick Multiple Commits At Once + +I've always thought of `git cherry-pick` as being a command that you can run +against a single commit by specifying the SHA of that commit. That's how I've +always used it. + +The man page for `git-cherry-pick` plainly states: + +> Given one or more existing commits, apply the change each one introduces, +> recording a new commit for each. + +We can cherry pick multiple commits at once in a single command. They will be +applied one at a time in the order listed. + +Here we can see an example of applying two commits to the current branch and +the accompanying output as they are auto-merged. + +```bash +$ git cherry-pick 5206af5 6362f41 +Auto-merging test/services/event_test.rb +[jb/my-feature-branch 961f3deb] Use the other testing syntax + Date: Fri May 2 10:50:14 2025 -0500 + 1 file changed, 7 insertions(+), 7 deletions(-) +Auto-merging test/services/event_test.rb +[jb/my-feature-branch b15835d0] Make other changes to the test + Date: Fri May 2 10:54:48 2025 -0500 + 1 file changed, 7 insertions(+), 7 deletions(-) +``` + +If the commits cannot be cleanly merged, then you may need to do some manual +resolution as they are applied. Or maybe you want to try including the +`-Xpatience` merge strategy. + +See `man git-cherry-pick` for more details. Make sure to look at the _Examples_ +section which contains much more advanced examples beyond what is shown above.