Checkout old commit to temporary directory with 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.

  • How can I review or secure remote branch deletions?
  • Can you clone an OpenShift application repo via HTTPS instead of SSH?
  • git: 'aws.push' is not a git command when trying to push a repository to Amazon Elastic Beanstalk on Mac
  • Composer => WordPress plugin workflow
  • GIT - How to know the branch a branch branched from?
  • Git: Teamwork across branches without Push Permission
  • When is git rm -f used?
  • git: number of lines *not* changed since specific commit?
  • How do Git SVN ignore-paths work (ignoring daily build tags)?
  • Merging selected files from similar branches after one was rebased
  • how do you use virtual-dom gist in browser?
  • Git command to commit all changes including files removed or created
  • 2 Solutions collect form web for “Checkout old commit to temporary directory with git”

    cd /home/user/Workspace
    git clone MyProject MyProject_OldCommit
    cd MyProject_OldCommit
    git checkout <old_sha1>
    

    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.

    Git Baby is a git and github fan, let's start git clone.