I've done some work on a project but then realized it wasn't the way to go. So I want to go back to an earlier, clean, revision. However, I do not want to lose the work I've done between this clean revision and today, so that I can refer to it later if I change my mind.
What would be the best way to handle this in git?
You have two reasonable options:
Use git-stash. Just type git stash
to stash, or git stash save some descriptive message
to give it a descriptive message. You can then reapply this later with git stash apply
(or git stash pop
).
Make a commit, drop a tag on it, then reset back to parent. You can then retrieve your work later by accessing the tag. This would be git commit -m 'Temp work'; git tag tempWork; git reset --hard HEAD^