git 提交丢失Warning, you are leaving 2 commits behind,

本文介绍了一种在Git中找回未连接到任何分支的丢失提交的方法。通过使用`git reflog`命令,可以查看历史记录并恢复这些提交,确保代码更改不会丢失。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

早上在自己的一个版本代码上编辑,提交commint,但是checkout到其他分支再checkout回来发现该的东西不见了,

幸好terminal还没有关掉,回看日志:

Warning: you are leaving 2 commits behind, not connected to
any of your branches:

  ****** update
  ****** 增加flask中间服务文件

If you want to keep them by creating a new branch, this may be a good time
to do so with:

 git branch <new-branch-name>   ******

然后就将刚刚修改的创建新分支就好,

 git branch <new-branch-name>   ******

但是,如果当时终端关闭了或者其他原因没有找到呢?

其实,只要你commint了,git本地是保存了这个变化的,就是没有一个分支链接到这种变化,可以使用:

git reflog show HEAD@{now} -10
****** HEAD@{Fri Jul 27 11:24:56 2018 +0800}: checkout: moving from ******
****** HEAD@{Fri Jul 27 11:19:43 2018 +0800}: checkout: moving from master to 1a
****** HEAD@{Fri Jul 27 11:17:55 2018 +0800}: checkout: moving from develope to master
****** HEAD@{Fri Jul 27 11:17:40 2018 +0800}: checkout: moving from****** to develope
****** HEAD@{Fri Jul 27 11:16:16 2018 +0800}: checkout: moving from master to 1a
****** HEAD@{Fri Jul 27 11:15:50 2018 +0800}: checkout: moving from****** to master
****** HEAD@{Fri Jul 27 11:12:54 2018 +0800}: commit: update
****** HEAD@{Fri Jul 27 10:36:07 2018 +0800}: commit: 增加flask中间服务文件
****** HEAD@{Thu Jul 26 16:34:14 2018 +0800}: checkout: moving from develope to 1a
****** HEAD@{Thu Jul 26 16:34:09 2018 +0800}: commit: update hello.py

然后跟据当时的commit信息找到编号,再

 git branch <new-branch-name>   ******

可见,认真写好每个commint 信息是多重要!!!!!

 

转载于:https://www.cnblogs.com/YouXiangLiThon/p/9376674.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值