Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fix commits when you commit on the wrong branch
git checkout -b 'feature-a'
 - git commit -m 'working on feature a'
 - git commit -m 'working on feature a'
---
 - git commit -m 'working on feature b'
 - git commit -m 'working on feature b'
 - git commit -m 'working on feature b'
---

git checkout master
---
crap just realized I commited on the wrong branch!

# get my commits on the right branch:

git checkout -b 'feature-b'
git cherry-pick sha1 for feature-b commit
git cherry-pick sha2 for feature-b commit
git cherry-pick sha3 for feature-b commit

# remove my commits from the wrong branch:
git checkout 'feature-a'
git revert sha1 for feature-b commit
git revert sha2 for feature-b commit
git revert sha3 for feature-b commit

git push upstream feature-a
git push upstream feature-b 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment