Home > Enterprise >  Switch to older commit without changing anything
Switch to older commit without changing anything

Time:03-31

If i want to have a look at an older commit by switching to it, browse it in the IDE or run the code and test it what option is correct? I dont want to change anything or cause any kind of commit. I just want to switch to any commit and study it. Ive looked through commands like:

Checkout
Cherry pick
Revert
Reset

But none of the descriptions made me sure it would do what i need.

If anyone can also answer how to do it with Github Desktop that would be an appreciated bonus but its not the main question.

CodePudding user response:

I dont want to change anything or cause any kind of commit.

It is not fully clear what you mean by not wanting to change anything or cause any kind of commit.

A git checkout <branch-name or SHAID> will change "stuff" (will change working tree or the HEAD leading to a detached-HEAD situation).

If you have the SHAID of any commit and would like to extract that into a temporary folder outside of source control, here is something that you can use:

git archive <SHAID> | tar -xC GitExtracts/

The above will create an archive of the commit corresponding to <SHAID> and extract that into folder GitExtracts/. This is assuming GitExtracts is excluded from any source control. You can use it as a temporary folder and infact delete its contents before running the above command.

See also this thread: Git -- cloning a previous commit in a different folder than local working directory

CodePudding user response:

The easiest for you is to use git checkout <commit hash>. This will reset the state of the repository to that commit and you can switch back to the current state with git switch - (or git checkout <branch>)

It is also possible to do with git reset --hard <commit hash>, but switching back to the original state is harder (as the reset will alter your local branch)

  •  Tags:  
  • git
  • Related