Sometimes I don’t realize I’m on the master branch in git and don’t realize it and I end up committing something to master when I want to commit it to another branch, dev.
What I’ve been doing in this case is just copy the file somewhere else, checkout dev, copy the file back, and commit.
I’m sure there is a better way of doing this isn’t there?
The dev branch is just going to be merged into master anyways. Could I just git merge master on the dev branch? There are some branch specific changes that don’t seem to get merged when I do git merge dev on master. Will those changes get messed up if I merge master into dev?
git cherry-pickis what you’re looking for.Say, you committed to
masterrevisionAand want to haveAondevinstead:Done. Now,
Ais indev.We still have to get rid of
Ainmaster. IfAwas the last commit you did, this one will help:If there are some more commits since
A, you could eithergit rebase A~and deleteAthen or – if you pushed to somewhere else – simplygit revert A.