【删除分支】
1.删除本地分支: git branch -D br
2.删除远程分支: git push origin :br (origin 后面有空格)
【回滚本地分支】
1.git reset --hard commit-id :回滚到commit-id,将commit-id之后提交的commit都去除
2.git reset --hard HEAD3:将最近3次的提交回滚(HEAD3可以改写成HEAD^^^)
【回滚远端分支】
1、git checkout the_branch
2、git pull
3、git branch the_branch_backup //备份一下这个分支当前的情况
4、git reset --hard the_commit_id //把the_branch本地回滚到the_commit_id
5、git push origin :the_branch //删除远程 the_branch
6、git push origin the_branch //用回滚后的本地分支重新建立远程分支
7、git push origin :the_branch_backup //如果前面都成功了,删除这个备份分支
【开发中临时加塞了紧急任务处理 或 修改程序出现问题,想要回去以前版本查看,而又不想丢失工作区和暂存区的代码】
1、git stash 或者 git stash save "注释" 将没有提交的内容(包括工作区和暂存区)保存至堆栈中
2、git branch a 切换紧急任务分支(a分支),若是查看之前版本不涉及分支切换这步不需要
3、git stash list 列出所有保存的临时提交(stash)
4、git stash pop 或 git stash apply 将当前stash中的内容弹出,并应用到当前分支对应的工作目录上。注:git stash pop将堆栈中最近保存的内容删除(栈是[先进后出]), git stash apply 不会删除堆栈中的内容,可多次应用到工作目录中,适合多分支开发