git checkout <target_branch>
Use git cherry-pick
followed by the commit hash you want to apply:
bash
git cherry-pick <commit_hash>
Resolve any merge conflicts if they occur. Git will pause the cherry-pick process if there are conflicts and allow you to resolve them manually.
Once conflicts are resolved, continue the cherry-pick process by running:
bash
git cherry-pick --continue
Alternatively, you can abort the cherry-pick if you encounter issues:
bash
git cherry-pick --abort
Here's an example:
Suppose you have a branch featureA
with a commit A
that you want to apply to your main
branch.
Identify the commit hash of commit
A
:bash
git log
Switch to the main
branch:
bash
git checkout main
Cherry-pick commit A
:
bash
git cherry-pick <commit_hash_of_A>
Resolve conflicts if any.
Continue or abort the cherry-pick process as needed.
After the cherry-pick is complete, the changes from commit A
will be applied to your main
branch, allowing you to incorporate specific changes from one branch into another without merging the entire branch.
No comments:
Post a Comment