git 查看和删除分支
查看本地分支:
hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (fix_view_task) $ git branch dev * fix_view_task master
查看所有分支:(本地和远程)
hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (fix_view_task) $ git branch -a dev * fix_view_task master remotes/origin/dev remotes/origin/fix_view_task remotes/origin/master
操作过程:
在gitlab远程的dev分支的一个commit节点创建 fix_view_task 分支,本地同步下远程的变化,本地切换到 fix_view_task 分支进行开发,bug修改完后,本地切换到 dev 分支,将 fix_view_task 分支的修改合并到 dev 上,然后将 dev 推到远程,然后jenkins 从远程dev分支拉取进行构建。此时我认为 fix_view_task 分支已经没有用了,我需要对它进行删除操作。。。
删除本地 fix_view_task :
hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (fix_view_task) $ git branch -d fix_view_task error: Cannot delete branch 'fix_view_task' checked out at 'D:/project/js/iot-mis-web/code/iot-mis-web' hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (fix_view_task) $ git checkout dev Switched to branch 'dev' Your branch is up to date with 'origin/dev'. hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (dev) $ git branch -d fix_view_task warning: deleting branch 'fix_view_task' that has been merged to 'refs/remotes/origin/fix_view_task', but not yet merged to HEAD. Deleted branch fix_view_task (was 5e79554).
删除远程 fix_view_task(方式一) :
命令记忆技巧:git push [远程名] [本地分支]:[远程分支],这个命令是用本地分支创建一个远程分支,如果本地分支为空,则意味着删除对应的远程分支
hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (dev) $ git push origin :fix_view_task # 注:origin后边有个空格 To 172.16.79.20:front-end/iot-mis-web.git - [deleted] fix_view_task
删除远程 fix_view_task(方式二) :
hs@DESKTOP-L2NPMSM MINGW64 /d/project/js/iot-mis-web/code/iot-mis-web (dev) $ git push origin -d fix_view_task To 172.16.79.20:front-end/iot-mis-web.git - [deleted] fix_view_task
可能遇到的问题:
比如: remote ref does not exist ,遇到这个问题的话是本地和远程之间的关联有问题了,我们在删除前先执行下 git fetch -p origin