Git - temporarily switch between
I've already looked at: Temporarily switch your working copy to a specific Git commit . Can I switch between Git commits? Git switching between commits However, I would like to understand a specific topic:
I am not currently working in a team,
I am using Git to save the history of a project locally (no GitHub or Bitbucket) and only has a master branch,
I am not PUSH, my commit is outside of .git in my working directory until the end of the project. My question is simple:
how can I safely revert to one of my previous commits (time machine) without intending to break the existing tree indexes?
how can I ensure that files added after this particular commit are not present in the working directory during this experiment?
how can I safely go back to the HEAD of the tree and once again - make sure that files deleted after this particular commit in the past (a long time ago, not this time) will not be present in the working directory?
The reason I am asking this is simple: I am currently studying and therefore want to come back from time to time to review (read-only) what was in the past (say a month ago).
Thank.
source to share
One simple solution:
- clone your repo locally again
- experiment in this new clone
Thus:
- your original repo remains on the server
- you can do
git checkout anOldCommitSHA1
as you want in the second repo
You can stay in the main repo and checkout whatever older commit you want, but:
- do a
git stash
before (to make sure any work isn't working) - do
git clean -d -f -x
after (when the checkout wizard again) to clean up any local file you might have generated using the old commit tree.
source to share