gitpractice.dev

brewly — Ch.7 · Copy several commits

Exercise 5 of 6

Before you start

Ranges and conflicts

git cherry-pick A..B copies every commit after A up to and including B, oldest first.

If one conflicts, solve the file, git add it and run --continue. Git then carries on with the rest. --abort returns to where you started.

-x adds a line to each message saying which commit it was copied from.

git log --oneline <branch>
find the ends of the range
git cherry-pick <older>..<newer>
copy the commits in between
git add <file>
mark a conflict solved
git cherry-pick --continue
commit it and go on
git cherry-pick --abort
give up
You can reopen this any time with “Lesson”.

Continue on a desktop

Typing git on a small screen is no fun. Open this page on a laptop or desktop to practise.

Back to the path