Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git恢复单个文件 #38

Open
Bobjoy opened this issue Sep 3, 2020 · 0 comments
Open

git恢复单个文件 #38

Bobjoy opened this issue Sep 3, 2020 · 0 comments

Comments

@Bobjoy
Copy link
Owner

Bobjoy commented Sep 3, 2020

git恢复单个文件

  1. 查询提交记录
$ git log --pretty=oneline -2
be4a7bf7fbb010e058b9cfd604e3bcd2cb04795b add line a in both file
52b7b10c3aaa2acf278827a229d308cfcb0b1cb8 init
  1. 指定恢复到哪个版本
$ 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
  1. 查询修改状态
$ 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
#
  1. 恢复文件
$ 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
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant