赞
踩
问:reset --hard 后如何找回
答:拢共分两步
一:找到你想要切回的commit-id
二:切过去
————————————————————————————————————
你的git操作在log中都会有记录
.git/logs/refs/heads/master
如:
- ***@***:~/GIT/StudyGit$ git log --oneline -5
- 6a851f1 (HEAD -> master, origin/master, origin/HEAD) update main.cpp.
- 35a96a6 add 1.txt
- d57b460 Merge branch 'master' of https://gitee.com/qiaoyuhu/StudyGit
- ebe2a1b add amend.test add amend.test to test git commit --amend add make.sh
- fe4c3e5 qiong add condition.cpp
- ***@***:~/GIT/StudyGit$ git log --oneline -5
- 9933cb9 (HEAD -> master) update main.cpp.
- 35a96a6 add 1.txt
- d57b460 Merge branch 'master' of https://gitee.com/qiaoyuhu/StudyGit
- ebe2a1b add amend.test add amend.test to test git commit --amend add make.sh
- fe4c3e5 qiong add condition.cpp
- ***@***:~/GIT/StudyGit$ git reset --hard HEAD~
- HEAD is now at 35a96a6 add 1.txt
- ***@***:~/GIT/StudyGit$ git log --oneline -5
- 35a96a6 (HEAD -> master) add 1.txt
- d57b460 Merge branch 'master' of https://gitee.com/qiaoyuhu/StudyGit
- ebe2a1b add amend.test add amend.test to test git commit --amend add make.sh
- fe4c3e5 qiong add condition.cpp
- 3ea8ae6 add amend.test add amend.test to test git commit --amend
- ***@***:~/GIT/StudyGit$ cat .git/logs/refs/heads/master
- 0000000000000000000000000000000000000000 6a851f16798a0a22e0a7d93891ed8af8f0d74126 qiaoyuhu <qiaoyuhu@axera-tech.com> 1665715932 +0800 clone: from https://gitee.com/qiaoyuhu/StudyGit.git
- 6a851f16798a0a22e0a7d93891ed8af8f0d74126 9933cb919ab0fe6702e852375a6085fec74e4020 qiaoyuhu <qiaoyuhu@axera-tech.com> 1665716114 +0800 commit (amend): update main.cpp.
- 9933cb919ab0fe6702e852375a6085fec74e4020 35a96a66f135914638f298a75a20a6b5c4f6e4cc qiaoyuhu <qiaoyuhu@axera-tech.com> 1665716183 +0800 reset: moving to HEAD~
这个文件就是你所有操作的记录
解读如下:
记录1: clone操作 ,commit id 从 (0000——> 6a851f1)
记录2:commit (amend)操作,commit id 从(6a851f1——>9933cb9)
记录3:reset 操作,commit id 从(9933cb9——>35a96a6)
剩下的你想切到哪次提交,直接git checkout commit-id 就行
git checkout 6a851f1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。