DEV Community

Discussion on: 5 scary Git commands you'll eventually have use for

Collapse
 
jingxue profile image
Jing Xue • Edited

I would not recommend using soft reset to fix commits on the wrong branch, especially with multiple commits. You end up with all the changes back to uncommitted, and having to sort through them in order to recreate the commits.

Say you meant for a series of commits, commit1 thru commit2, to be on branch1, but accidentally made them on branch2, to fix it, simply do:

git switch branch1
git cherry-pick commit1~..commit2
git switch branch2
git reset --hard commit1~
Enter fullscreen mode Exit fullscreen mode