Before executing this command, keep in mind that it will leave you in a detached head state.
Use git checkout <sha1> to check out a particular commit.
Where <sha1> is the commit unique number (SHA-1 hash value) that you can obtain with git log.
Here is what you could do after you are in the detached head state:
Copy the files or make the changes that you need to a folder outside your Git folder, check out the branch where you need them git checkout <existingBranch> and replace files.
Otherwise, you could do the following to get a copy of the project in the state that you want without getting into the detached head state:
Create a new local branch git checkout -b <new_branch_name> <sha1>
Note: to "undo" (return from) the detached head state, simply use:
git checkout <branch> (where <branch> is e.g. master).
Before executing this command, keep in mind that it will leave you in a detached head state.
Use git checkout <sha1> to check out a particular commit.
Where <sha1> is the commit unique number (SHA-1 hash value) that you can obtain with git log.
Here is what you could do after you are in the detached head state:
Copy the files or make the changes that you need to a folder outside your Git folder, check out the branch where you need them git checkout <existingBranch> and replace files.
Otherwise, you could do the following to get a copy of the project in the state that you want without getting into the detached head state:
Create a new local branch git checkout -b <new_branch_name> <sha1>
Note: to "undo" (return from) the detached head state, simply use:
git checkout <branch> (where <branch> is e.g. master).
To go to a particular version/commit, run the following commands. You can get HASH-CODE from git log --oneline -n 10:
git reset --hard HASH-CODE
Note - After resetting to a particular version/commit, you can run git pull --rebase, if you want to bring back all the commits which are discarded.
I asked someone what version of a repo they used for an analysis and they gave me a hash for a commit.
Is this the correct way to access the version they used?
-
git clone https://github.com/foo.git
-
cd foo
-
git checkout -b bar <hash she gave me>
This should give me the repo in the state of the commit hash she gave me correct?
Something got screwed up at work and our tests isn't passing. The tests were passing about a week ago. I need to checkout commits from last week to identify the issue, but when checking out commits I need to ensure that the commit is a reflection of what our project's code looked like a week ago; in other words, I don't want to roll back on just one file, I'd like to roll back the entire project.