Reputation: 1744
I'm trying to go back to a different date on the branch i'm working on.( like 3 days ago) I've created a patch of the files i have changed so i don't mind if it will be override.
Thanks in advance,
Upvotes: 1
Views: 205
Reputation: 2223
You just need to see your git log and get the sha hash of the commit you want to got to and do a git checkout.
In your case, your git log need to focus on the time, where changes happen, like 3 days ago. So something like below will help you.
$git log --pretty=format:"%h - %an, %ar : %s"
will give something like this
$387820f - var_j, 25 hours ago : Rust Lessons: variables
$72a4abc - var_j, 25 hours ago : Rust Lessons: loops
$f272f95 - var_j, 25 hours ago : rust lessons: hello world added
And then,
$git checkout 387820f
this will detach head and move it to the particular state, so the working copy will also get updated accordingly.
And if you really want to go back in time, consider
$git reset --soft <commit_hash>
git reset --soft
Does not touch the index file nor the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.
But be careful using git reset, it can cause damage. Read the doc and decide what you need.
Upvotes: 3
Reputation: 17042
This is how you can checkout your code to a previous commit you've made back in time.
git log
to see all your past commits and choose the one you want to revert toaefd2efc660f4gb2fa2d7r1ef73b3z4e2b4498e5
)git checkout aefd2efc660f4gb2fa2d7r1ef73b3z4e2b4498e5
Upvotes: 3