Undo git mv (rename)

In my case, I moved an entire folder, then realized I should not have.

I really liked @Dave Konopka's answer, but I did not have much success with that approach (maybe my version of GIT (1.8.4)? My files still showed as deleted. I had other changes on the stack that I did not want to lose (unfortunately).

I did have success doing this:

git reset moved_folder
git checkout original_folder

git reset HEAD file2

did the trick for me


If you have done no other changes (that you want to keep) since the last commit, you can do

git reset --hard

Non-cheeky answer:

git mv file2 file1

Updates the index for both old and new paths automatically.

Check documentation of git mv

Tags:

Git

Undo

Rename

Mv