0

I have done a git rm -r path/. I have commit it, and after that I have seen that I have not done git rm --cached. I have searched for going back, and I have done also: git reset --soft 'HEAD^' 2 times. Now I see that I have got back on my git tree, but I do not see the removed files...

* <I_do_not_know_the_head> commit after removing files   (1)
* <I_do_not_know_the_head> commit before removing files  (2)
* <I_do_know_the_head> current commit                    (3)
* ... other commits                                      (4)

I am now at (3) and I do not see the commits (1) and (2). I want to get to back (1) and then get the removed files. The problem is that I think I have done some other changes, too, not just removed those files.

How to go back to the last commit and then just add the removed files? Please help, I do not want to loose commits.

user229044
  • 232,980
  • 40
  • 330
  • 338
thedarkside ofthemoon
  • 2,251
  • 6
  • 31
  • 48

1 Answers1

2

--soft is your problem. That leaves the working directory in its current state. You want --hard.

git reset --hard <commit_id_of_2>

Why do I want --hard? I do not have the id of 2..

You want --hard because that moves the working directory to the state of the commit you're moving to.

You'll have to use git reflog to figure out the commit ID of the commit you want to go back to. There are tons of questions on here about how to use git reflog if git reflog --help isn't enough.

user229044
  • 232,980
  • 40
  • 330
  • 338