-1

I want to revert to my previous commit (commit 4d462937b006da1fbc710bc33bf3bab76de1ede2) with all my files (some of them were deleted)

(venv) [ndale@my_arch project]$ git log

commit d0b07921e818c5c5abdb92f0e563f4d186370b6f
Author: Nikos Dalezios <ndalezios@gmail.com>
Date:   Tue Mar 1 21:03:11 2016 +0200

    test

commit 4d462937b006da1fbc710bc33bf3bab76de1ede2
Author: Nikos Dalezios <ndalezios@gmail.com>
Date:   Sun Feb 28 20:07:01 2016 +0200

    ok



(venv) [ndale@my_arch project]$ git reflog
d0b0792 HEAD@{0}: pull origin master: Fast-forward
4d46293 HEAD@{1}: reset: moving to 4d46293
e0e0368 HEAD@{2}: reset: moving to HEAD^
4d46293 HEAD@{3}: reset: moving to 4d46293
d0b0792 HEAD@{4}: checkout: moving from 4d462937b006da1fbc710bc33bf3bab76de1ede2 to d0b0792
4d46293 HEAD@{5}: checkout: moving from master to 4d46293
4d46293 HEAD@{6}: reset: moving to HEAD^
d0b0792 HEAD@{7}: commit: test
4d46293 HEAD@{8}: commit: ok

I really messed things up, and I lost a few files of python code (a few hundred lines). HEAD@{8} is the point where I need to go back.....

Thanks

I don't know if this helps but my command history is this

git rm -r *
git reset --hard HEAD
git reset HEAD
git commit -a
git reset --hard HEAD^
git checkout 4d46293
git checkout d0b0792
git reset --hard 4d46293
git reset --hard HEAD^ #4d46293
Nikolaos Dalezios
  • 1,006
  • 6
  • 9

2 Answers2

1

If you haven't pushed your commits up to your remote repository yet (Github, Bitbucket, etc..) then you can use

git reset --hard 4d462937b006da1fbc710bc33bf3bab76de1ede2

This essentially removes any records related to your commit.

If, on the other hand, you have already pushed your commit to a remote repository, then you'll want to do

git revert 4d462937b006da1fbc710bc33bf3bab76de1ede2

which undo your changes and records this undo in the commit history.

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248
0

git reset --hard 4d462937b006da1fbc710bc33bf3bab76de1ede2

Keyne Viana
  • 6,194
  • 2
  • 24
  • 55