Git – temporarily switch between

I have already looked through:
Temporarily switch working copy to a specific Git commit
Is it possible to switch between GIT commits?
Git switching between commits
However, I would like to sort out a specific topic:

I do not work in a team at present,

  • Git: how to change active branch on remote repository?
  • git rev-parse --verify says “fatal: Needed a single revision”
  • Git checkout can't auto-complete with bash
  • practical git commands to compare/diff between various branches
  • How to use Winmerge with Git Extensions?
  • Git Shell: How can we remove specific file from untracked files
  • I use Git to save my project history locally (no GitHub or Bitbucket) and have only master branch,

    I don’t PUSH my commits outside .git in my working directory until end of project.
    My question is simple:

    how can I safely return to one of my previous commits (kinda time machine) not having in mind to break existing tree indexes?

    how can I ensure that files added after this specific commit will not be present in the working directory during this experiment?

    how can I then safely return to HEAD of tree and once again – ensure that files deleted after that specific commit in the past (long time ago, not this time) will not be present in the working directory?

    The reason I am asking about this is simple: I am learning now and therefore would like from time to time get back for a while to see (read-only) – what happened in the past (say a month ago).

    Thank you.

  • How does version control with LabVIEW VIs work?
  • Git allow to lose file changes history during merge with conflicts
  • How to update/shrink the size of my github repo after running BFG Repo Cleaner
  • Is it possible to have a GitHub repo with two branches that contain different directories on my local machine?
  • How do I place my entire WordPress installation under git control?
  • Repository naming conventions for web application
  • 2 Solutions collect form web for “Git – temporarily switch between”

    I think this does what you’re 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 stash ignored files as well.

    One simple solution is to:

    • clone again your repo locally
    • experiment in that new clone

    That way:

    • your original repo remains on master
    • you can do git checkout anOldCommitSHA1 as you want in the second repo

    You can remains in the main repo and checkout any older commit you want but:

    • do a git stash before (to make sure any work in progress is stash away)
    • do a git clean -d -f -x after (when checkout master again) to clean any local file you might have generated while using the old commit working tree.
    Git Baby is a git and github fan, let's start git clone.