Git 出错了怎么办(急救)
rebase 冲突、提交错分支、误删分支的补救方法。
模板正文
# 提交到了错误的分支(还没 push) git branch feat/right # 先在新分支上留下这个提交 git reset --hard HEAD~1 # 再把这个分支回退一步 git switch feat/right # rebase 中途想放弃 git rebase --abort # 冲突解决完继续 git add <file> && git rebase --continue # 误删了分支 git reflog # 找到那次的 commit hash git switch -c <branch> <hash> # 用 hash 把分支恢复出来 # 临时保存手头的改动 git stash push -m "半成品" git stash pop
怎么用
出事时按情况查,先别慌着删仓库。
使用要点
- reflog 是你的后悔药,只要没被 GC 掉,几乎什么都能找回来。
- 冲突时先看 git status 的提示,它会告诉你下一步该做什么。