Git异常处理

本地工作区文件恢复

1
git checkout <filename/dirname>

远程分支删除后,删除本地分支及关联

1
2
3
git branch --unset-upstream <branchname>

git branch --unset-upstream feature/test

修改提交时的备注内容

1
2
3
git commit --amend

git log --pretty=online

修改分支名

1
2
3
git branch -m <oldbranch> <newbranch>

git branch -m feature/stor-13711 feature/story-13711

撤回提交

1
2
3
4
5
6
7
git reset --soft [<commit-id>/HEAD~n]

git reset --soft HEAD~1

git reset --mixed HEAD~1

git reset --hard HEAD~1

撤销本地分支合并

1
git revert <commit-id>

恢复误删的本地分支

1
2
3
git checkout -b <branch-name> <commit-id>

git checkout -b feature/delete HEAD@{2}

不确定哪个根治有自己提交的commit

1
git branch --contains <commit-id>