duhan
Blog

Move Commits from Wrong Branch

Problem:

  • Branched x from dev, committed.
  • Should’ve branched from qa.
  • Now you created y from qa. Want to move x’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

🔗 Related posts