Atomic commits really help cherry picking.
When you have multiple commits that you need to apply to a separate release branch with mixed commit history, you need to cherry-pick individual commits in sequential order to apply them correctly to the release branch.
# HEAD at release branch git cherry-pick commit_sha_1 # from main branch git cherry-pick commit_sha_2 # from main branch git cherry-pick commit_sha_3 # from main branch
When you want to apply a single commit from another branch into current branch.
gitGraph commit commit branch develop checkout develop commit commit id: "123" commit checkout main commit cherry-pick id: "123" commit
graph LR A1["a"] --> A2["b"] A2 --> A3["c"] A3 --> A4["d"]
You cannot pull specific commit from a remote; you can instead fetch the data and merge or cherry-pick
git fetch origin
View the code at specified commit_sha
or branch name (if tip of branch includes the commit you want):
git checkout commit_sha
Bring only the commit_sha
to the destination_sha
branch:
git checkout destination_sha && git cherry-pick commit_sha
Bring all the changes leading up to commit_sha
to the destination_sha
branch:
git checkout destination_sha && git merge commit_sha