Making "git reset" effective without using "--hard" option

86 Views Asked by At

I am using git reset to navigate backward in my git tree; however, except the time that I use --hard option, my files do not get back to their earlier versions. As an example I made a file called f1.txt and in every commit, I added a character to it, but when I use git reset --mixed or git reset --soft commands, they do not change the content of f1.txt and all the characters are there (although when I use git log, I see that the HEAD has moved back).

2

There are 2 best solutions below

4
On BEST ANSWER

You cannot use git reset to navigate through your tree.
git reset will reset the "stage" (what is committed when you git commit). So if you do git add and want to undo that, you use git reset.
If you do git reset --hard HEAD it will also reset the file to the status of HEAD.

To navigate through the tree, you need to use git checkout <branch/commit>. It you do not want to checkout the commit, but just get the one file from a previous commit, you can do git checkout <branch/commit> -- path/to/file.

Checkout the docs:

0
On

I think you'd better use git checkout than git reset for navigating. You can use git checkout with a commit SHA1.