1

After committing changes, I ran git reset --hard HEAD^ mistakenly and it caused me to lose the files in that committed changes.

I am trying to recover these files.

When I do git reflog it shows that previous commit, thatCommit, so I then proceed with:

git checkout thatCommit

However, none of the files are restored.

When I then type git checkout it prints out all the files that have been deleted:

D path/to/deletedFile1 D path/to/deletedFile2 M path/to/changedFile1 M path/to/changedFile2 

I'd like the deleted files and changed files to be restored, but I cannot see path/to/deletedFile1 in my repo/branch.

How can I recover these files?

1 Answer 1

2

Try

git checkout thatCommit -- . 

(to force the working tree to be reinitialize to that commit content)

Or:

git reset --hard thatCommit 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.