Move Commits from Wrong Branch
—
Let’s assume you have 2 main branches: dev
and qa
.
Problem:
- Branched
X
from dev, committed. - Should have branched from qa.
- Now you created
Y
from qa. Want to moveX
’s commits there.
# Get commit hash(es) from X
git log --oneline X
# Switch to Y
git checkout Y
# Apply commits
git cherry-pick <hash>
# or for a range:
git cherry-pick <start>^..<end>
Cleanup:
git branch -d X
Verify:
git log --oneline
git diff qa..Y