Tiina
Tiina

Reputation: 4797

git how to recover the last commit files

After I commit some files, the local files are changed. And now I want to recover the local directory to exactly the same as last time commit. In the following figure, local uncommitted changes corrupted, so I want to take out the master basic operators.... I have already tried git reset [the first commit hash code from git log], but nothing changes.

enter image description here

Upvotes: 1

Views: 414

Answers (2)

Sajib Khan
Sajib Khan

Reputation: 24194

I want to recover the local directory to exactly the same as last time commit. In the following figure, local uncommitted changes corrupted

If you want to discard your local uncommitted changes then do reset HEAD (back to the last commit)

$ git reset --hard HEAD

Upvotes: 1

jbu
jbu

Reputation: 16161

git reset <commit> changes where your HEAD points to but doesn't restore your files to how they were at that commit. If you want to restore the files to how it looks at the commit, you need git reset --hard <commit>

About the three reset modes:

       --soft
           Does not touch the index file or the working tree at all (but
           resets the head to <commit>, just like all modes do). This
           leaves all your changed files "Changes to be committed", as git
           status would put it.

       --mixed
           Resets the index but not the working tree (i.e., the changed
           files are preserved but not marked for commit) and reports what
           has not been updated. This is the default action.

           If -N is specified, removed paths are marked as intent-to-add
           (see git-add(1)).

       --hard
           Resets the index and working tree. Any changes to tracked files
           in the working tree since <commit> are discarded.

Upvotes: 0

Related Questions