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.

+3


source to share


2 answers


I think this does what you are looking for.

git stash --include-untracked
git checkout <commit>

git checkout master
git stash pop --index

      



For a completely clean working tree, you can replace --include-untracked

with --all

to ignore files as well.

+3


source


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:

0


source







All Articles