[Git] Recover Local Changes from `git reset --hard` with `git reflog`
Git -- with from local reset Hard recover
2023-09-14 08:59:14 时间
If you've removed a commit with git reset --hard
, it's still possible to recover the commit using git reflog
to look up the commit hash.
Once we find the right commit hash, we can reset our branch back to that commit hash with git reset --hard [HASH]
NOTE! git will actually garbage collect abandoned commits (every 30 days or so - so not very often) - so you can't recover from a reset --hard
forever; which is why it's recommended to avoid --hard
if you ever want to references those changes.
git reflog
Find the commit id which you want to recover then do:
git reset --hard [AHSH-id]
相关文章
- git pull --rebase
- [代码质量] Git统计本次提交新增代码行数,建议每个评审commit新增行数小于400行
- [Git] 根据commiter过滤该用户的所有提交
- [Git] git shortlog 找出最懒的程序员
- Git 代码更新:git fetch 和 git pull 的区别
- Git fetch和git pull的区别
- Git回滚远程版本
- 【学习总结】Git学习-参考廖雪峰老师教程十-自定义Git
- [Git] Use and Compare the Different git Reset Options: --hard, --soft, and --mixed
- [Git] Use git add --patch for better commit history and mitigating bugs
- [Practical Git] Remove unnecessary git tracking with .gitignore files
- [Practical Git] Configure global settings with git config
- [Practical Git] Clean up commits with git rebase
- [Practical Git] Format commit history with git log arguments
- jenkins 持续集成和交付 —— git hook(七)
- Git远程02:git clone都做了什么
- [Git] Use git add --patch for better commit history and mitigating bugs
- [Practical Git] Diagnose which commit broke something with git bisect
- 用git命令上传一个项目到gitee(git 2.30.2)
- git初级--配置
- git config --global core.editor “vim“
- 详谈Git常用命令大全
- Git知识总览(四) git分支管理之rebase 以及 cherry-pick相关操作
- 对git rebase 和git merge的理解
- 【Git总结大全】git操作从入门到实战(总结篇)
- 【Git技巧】第六篇 git常用命令速查表
- Git实战之git客户端上传文件到github
- Linux搭建Git服务器教程
- [Git & GitHub] git 常用命令