Sobes.tech
Junior — Middle

How can a specific commit from another branch be applied to the current one in Git?

sobes.tech AI

Answer from AI

To apply a specific commit from another branch to the current one, you can use the git cherry-pick command.

Example:

# Switch to the branch where you want to apply the commit
git checkout current-branch

# Apply the commit by its hash from another branch
git cherry-pick <commit-hash>

This will create a new commit in the current branch with changes from the selected commit of another branch, preserving history and allowing selective transfer of changes.