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
.
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.
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 .
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.
cd /home/user/Workspace
git clone MyProject MyProject_OldCommit
cd MyProject_OldCommit
git checkout <old_sha1>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With