0

I did not realize that git does not understand file renames (by design(!)) and moved some files around. Then I put them back. Now git log seems to work, but git log --follow does not. And Eclipse seems to use the latter. (git log --follow could not follow my renames.)

So what I want to do is somehow get HEAD back to where it was before I started. Throw away everything and then move forward as if it had never happened. (I have made some other changes since, I'll just make them again manually, no problem.)

git revert is not the answer. It will just push additional commits on top which will totally confuse the histories. I need the changes gone, or at least taken right out of the main line.

So I have done

git branch moveDead
git reset --hard 4902b024588678cd493929955f79c6405f6dab9d
git branch beforeMoves

All good. (branches just for future reference.)

But I cannot now push, as I had pushed the renamed files, not realizing the danger at the time. I need to reset the remote.

I am the main developer on this repository, so maybe we could restore the main git repository from a backup and then move it forward, but that would be awful.

(There are no branches or other complicating factors.)

Tuntable
  • 3,276
  • 1
  • 21
  • 26
  • Not an answer, but: git _does_ understand file renames, it just does not record them explicitly. `git blame` for example works perfectly fine even across renames. Consider using a different tool - Eclipse's git frontend is nice, but rather basic. – sleske Sep 28 '15 at 07:56
  • 1
    I wish people would stop saying that Git understand renames. It does not, and Linus considers the need for rename to be old subversion habits. git log with or without --follow may or may not follow renames provided the files were not also changed nor moved too far. But there is no record of the actual move kept. I have not checked blame but presume it follows the same logic as log. Git is broken in this respect, and I did not realize because so many people say it works. There are some rename hacks like https://gist.github.com/emiller/6769886 but I avoid them! – Tuntable Sep 28 '15 at 10:19

1 Answers1

1

If you haven't pushed your repository yet, you can do

git reset <commit-id> --hard

where commit-id is the commit that you want to go to (every child commit will be LOST)

edi9999
  • 19,701
  • 13
  • 88
  • 127