网络网站建设推广,微网站和微信,贵州省遵义市建设局网站,福田祥菱v2双排后双轮报价一.问题描述
当我们在操作中手误删除了某个分支#xff0c;那该分支中提交的内容也没有了#xff0c;我们可以利用git reflog这个命令来查看历史提交的记录从而恢复被删除的分支和提交的内容
二.模拟问题
1.创建git仓库#xff0c;并提交一个文件
[rootcentos7-temp /da…一.问题描述
当我们在操作中手误删除了某个分支那该分支中提交的内容也没有了我们可以利用git reflog这个命令来查看历史提交的记录从而恢复被删除的分支和提交的内容
二.模拟问题
1.创建git仓库并提交一个文件
[rootcentos7-temp /data]# git init
已初始化空的 Git 仓库于 /data/.git/
[rootcentos7-temp /data]# vim test.txt[rootcentos7-temp /data]# cat test.txt
11111[rootcentos7-temp /data]# git add test.txt
[rootcentos7-temp /data]# git commit -m first commit
[master根提交 af8a35f] first commit1 file changed, 1 insertion()create mode 100644 test.txt
2.再次编辑test.txt文件并提交
[rootcentos7-temp /data]# vim test.txt [rootcentos7-temp /data]# cat test.txt
11111
22222
[rootcentos7-temp /data]# git add test.txt
[rootcentos7-temp /data]# git commit -m second commit
[master 9f10533] second commit1 file changed, 1 insertion()
3.查看当前所处分支和提交记录
#可以看到所处分支是在master分支在master分支中有两条提交记录
[rootcentos7-temp /data]# git branch
* master[rootcentos7-temp /data]# git log
commit 9f105338768642dd9306f4e0d83897847894176a (HEAD - master)
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:55:48 2023 0800second commitcommit af8a35fd2647b15059297c4d18d18de89f14601b
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:52:58 2023 0800first commit4.创建并切换至新分支
[rootcentos7-temp /data]# git checkout -b main
切换到一个新分支 main
5.查看当前所处分支
[rootcentos7-temp /data]# git branch
* mainmaster6.在main分支上继续编辑test.txt文件并提交
[rootcentos7-temp /data]# vim test.txt [rootcentos7-temp /data]# cat test.txt
11111
22222
33333
[rootcentos7-temp /data]# git add test.txt
[rootcentos7-temp /data]# git commit -m third commit
[main 14cc0a8] third commit1 file changed, 1 insertion()
7.查看提交记录
[rootcentos7-temp /data]# git log
commit 14cc0a8bc11ddb183d15241858108da85507d13c (HEAD - main)
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 15:06:10 2023 0800third commitcommit 9f105338768642dd9306f4e0d83897847894176a (master)
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:55:48 2023 0800second commitcommit af8a35fd2647b15059297c4d18d18de89f14601b
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:52:58 2023 0800first commit8.切换到master分支下然后删除main分支
[rootcentos7-temp /data]# git checkout master
切换到分支 master[rootcentos7-temp /data]# git branch -D main
已删除分支 main曾为 14cc0a8。9.查看所有分支验证下main分支是否真的被删除了
[rootcentos7-temp /data]# git branch
* master
10.查看提交记录
#分支因为没有合并到master分支就被删除了。所以此时master分支没有main分支上做的新的修改记录
[rootcentos7-temp /data]# git log
commit 9f105338768642dd9306f4e0d83897847894176a (HEAD - master)
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:55:48 2023 0800second commitcommit af8a35fd2647b15059297c4d18d18de89f14601b
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:52:58 2023 0800first commit
三.恢复main分支
1.查看所有分支的操作记录对比之前在main分支查看的提交记录 2.根据main的最后一次提交记录来恢复main分支
[rootcentos7-temp /data]# git checkout -b main 14cc0a8
切换到一个新分支 main[rootcentos7-temp /data]# git branch
* mainmaster[rootcentos7-temp /data]# git log
commit 14cc0a8bc11ddb183d15241858108da85507d13c (HEAD - main)
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 15:06:10 2023 0800third commitcommit 9f105338768642dd9306f4e0d83897847894176a (master)
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:55:48 2023 0800second commitcommit af8a35fd2647b15059297c4d18d18de89f14601b
Author: zhanghongshun 748749875qq.com
Date: Sun Feb 12 14:52:58 2023 0800first commit