git checkout main Switched to branch 'main' Your branch is up-to-date with 'origin/main'. git branch -D my-branch Deleted branch my-branch (was 4e3cd85). echo oh noes, deleted my branch! oh noes, deleted my branch!
在这时候你应该想起了reflog, 一个升级版的日志,它存储了仓库(repo)里面所有动作的历史。
git reflog 69204cd HEAD@{0}: checkout: moving from my-branch to main 4e3cd85 HEAD@{1}: commit: foo.txt added 69204cd HEAD@{2}: checkout: moving from main to my-branch
$ git checkout -b my-branch-help Switched to a new branch 'my-branch-help' git reset --hard 4e3cd85 HEAD is now at 4e3cd85 foo.txt added ls README.md foo.txt
我想删除一个分支
删除一个远程分支:
git push origin --delete my-branch
你也可以:
git push origin :my-branch
删除一个本地分支:
git branch -D my-branch
有冲突的情况
首先执行 git status 找出哪些文件有冲突:
git status On branch my-branch Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md
在你解决完所有冲突和测试过后, git add 变化了的(changed)文件, 然后用git rebase –continue 继续rebase。