找回丢失的 commit 要记住不要慌 事情总有解决的方法
一开始在一个分支上修改代码
- git add -A
- git commit -m "修改"
- git push origin dev
发现提交不了,心急了,切换分支
- 发现之前的 commit 的 不见
- git reflog
- 找到 上次的 commit
$ git reflog b7057a9 HEAD@{0}: reset: moving to b7057a9 98abc5a HEAD@{1}: commit: more stuff added to foo b7057a9 HEAD@{2}: commit (initial): initial commit
- git reset --hard 98abc5a
- 发现commit 回来了
切换到远程分支 把刚才的分支合并到远程分支
在A 分支上 找出要合并的commit ID : 例如 0128660c08e325d410cb845616af355c0c19c6fe 然后切换到B分支上 git checkout B git cherry-pick 0128660c08e325d410cb845616af355c0c19c6fe
参考链接
找回Git中丢失的Commit
Git合并某个分支的一个commit到另一个分支
本作品采用《CC 协议》,转载必须注明作者和本文链接