Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout old commit to temporary directory with git

Tags:

git

My sources are at /home/user/Workspace/MyProject, and the git repository is at /home/user/Workspace/MyProject/.git.

Now I want to get an older commit, but get it in /home/user/Workspace/MyProject_OldCommit, because I don't want to change anything in directory MyProject.

like image 346
sashoalm Avatar asked Mar 06 '13 14:03

sashoalm


People also ask

How do you checkout to previous commit and push?

Summary. If you want to test the previous commit just do git checkout <test commit hash> ; then you can test that last working version of your project. If you want to revert the last commit just do git revert <unwanted commit hash> ; then you can push this new commit, which undid your previous commit.

What does the command git checkout Branchname do?

Assuming the repo you're working in contains pre-existing branches, you can switch between these branches using git checkout . To find out what branches are available and what the current branch name is, execute git branch .


2 Answers

Run this from /home/user/Workspace/MyProject:

git archive  <old-sha1> | tar -x -C ../MyProject_OldCommit

This will create a fresh copy of the commit, without the whole git repository.

like image 43
CharlesB Avatar answered Sep 30 '22 08:09

CharlesB


cd /home/user/Workspace
git clone MyProject MyProject_OldCommit
cd MyProject_OldCommit
git checkout <old_sha1>
like image 135
Tadeusz A. Kadłubowski Avatar answered Sep 30 '22 07:09

Tadeusz A. Kadłubowski