0

I have a feature branch ff which is based on main.

I want to bring changes made by a commit HEAD abcde on top of ff.

How can I do this?

asked Feb 13, 2025 at 10:39
7
  • git-scm.com/docs/git-cherry-pick Commented Feb 13, 2025 at 10:52
  • 2
    Yes, basically it's git checkout ff then git cherry-pick abcde (regardless of abcde being a commit hash or a branch name, which is unclear from your question). What do you call "a commit HEAD" here? Commented Feb 13, 2025 at 11:00
  • Following on @RomainValeri's steps, it's also possible, to avoid having to look for the commit id, to do git checkout ff; git cherry-pick HEAD@{1}. Commented Feb 13, 2025 at 11:34
  • And @RomainValeri is also to ask what you mean with HEAD abcde? Just in case, HEAD in git is always where you are standing. Commented Feb 13, 2025 at 11:35
  • 2
    I think the confusion might have been introduced early on from the svn jargon where HEAD is just the last revision of a repo. Commented Feb 13, 2025 at 12:45

1 Answer 1

0

Assuming you have checked out commit abcde directly, which means your HEAD is in a detached state, and you want to bring the changes made in that commit on top of your feature branch ff, you can use git cherry-pick.

git checkout ff
git cherry-pick abcde

git cherry-pick abcde takes the changes introduced in commit abcde and applies them as a new commit on top of your current branch ff. This ensures that you bring only that specific commit without affecting other commits from the branch it originally belonged to.

If you encounter merge conflicts, Git will pause the cherry-pick and allow you to resolve them. After resolving, run:

git cherry-pick --continue

If you want to abort the cherry-pick due to conflicts, use:

git cherry-pick --abort
answered Feb 15, 2025 at 11:25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.