admin管理员组

文章数量:1292219

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?

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?

Share Improve this question asked Feb 13 at 10:39 pippip 294 bronze badges 7
  • git-scm/docs/git-cherry-pick – dani-vta Commented Feb 13 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? – Romain Valeri Commented Feb 13 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}. – eftshift0 Commented Feb 13 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. – eftshift0 Commented Feb 13 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. – eftshift0 Commented Feb 13 at 12:45
 |  Show 2 more comments

1 Answer 1

Reset to default 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

本文标签: gitBring Changes from a commit HEAD into a branchStack Overflow