You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ git log --pretty=oneline -2
be4a7bf7fbb010e058b9cfd604e3bcd2cb04795b add line a in both file
52b7b10c3aaa2acf278827a229d308cfcb0b1cb8 init
指定恢复到哪个版本
$ git reset 52b7b10 b.txt #【我们需要b.txt回到init的状态,复制init的commit SHA值52b7b10】
warning: LF will be replaced by CRLF in b.txt.
The file will have its original line endings in your working directory.
Unstaged changes after reset:
M b.txt
查询修改状态
$ git status #【查看下状态,会发现b.txt有两种状态,不用理会】# On branch mytest# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: b.txt## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: b.txt#
恢复文件
$ git checkout -- b.txt #【现在只需要把b.txt恢复到修改之前,也就是init的状态就可以了】
$ git status #【再看下状态,和b.txt的内容】# On branch mytest# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: b.txt#
The text was updated successfully, but these errors were encountered:
git恢复单个文件
$ git log --pretty=oneline -2 be4a7bf7fbb010e058b9cfd604e3bcd2cb04795b add line a in both file 52b7b10c3aaa2acf278827a229d308cfcb0b1cb8 init
The text was updated successfully, but these errors were encountered: