Basic question but this happens to me all the time:
- Make changes in a
working-branch
- Switch to
master
git merge working-branch
git push
cap deploy
(to staging)- make a new cup of tea
then I come back and think of something else and start making some changes...while still on master.
What's an easy way to either:
- prevent direct edits on master (warning perhaps)
- to move all edits over to
working-branch
and clearmaster
so I can continue editing onworking-branch
- to spin edits into an entirely new branch
new-working-branch
and then discardworking-branch
?
Took a risk and tried recommendation in the latter part of "Branches" section of this page but that just wiped out ALL my edits!?! perhaps because after git branch dubious-experiment
and git checkout master
the git status
on both branches was identical (not 'clean' on master). So git reset --hard <SHA1sum>
wiped out all changes on both!?!
git branch dubious-experiment
M---N-----O----P---Q ("master" and "dubious-experiment")
git checkout master
# Be careful with this next command: make sure "git status" is
# clean, you're definitely on "master" and the
# "dubious-experiment" branch has the commits you were working
# on first...
git reset --hard <SHA1sum of commit N>