audrey kropic
audrey kropic

Reputation: 33

git checkout a version before a specific commit

I would like to checkout a version of a branch of a git repository before a specific commit was done. Just wondering about the syntax.

I know how to checkout a branch called 'develop' (as opposed to the master) by using the following syntax:

git remote add -t develop -f origin https://github.com/xy/xy.git

Just wondering how i can checkout this but before a specific commit was done a few weeks ago.

Upvotes: 2

Views: 7593

Answers (1)

Dave Zych
Dave Zych

Reputation: 21887

After you clone the repository, run a git log and find the commit hash of the commit you want to checkout. You only need the first 6 characters, so it will be something like a93fh67. From there, run

git checkout {hash}

Where {hash} is the commit hash you found. That will place you in a DETACHED HEAD state, where you can review the code. If you want to make changes, checkout a new branch using

git checkout -b MyNewBranchName

Upvotes: 3

Related Questions