一、删除分支
在使用git 管理仓库代码的时候,会遇到分支过多难以分辨的苦恼,需要删除部分分支,以下为git 命令:
# 查看本地包含哪些分支以及当前分支,带*为当前分支
git branch
* dev-union-image
label-layer-count
master
pre-merge
# 删除本地分支
git branch -d label-layer-count
Deleted branch label-layer-count (was b812577).
# 若无法删除,使用
git branch -D label-layer-count
# 删除远程分支(!!!慎用)
git push origin --delete label-layer-count
To http://gitlab.com/xxx/yyy.git
- [deleted] label-layer-count
二、合入另一分支
在开发过程中,会有开发分支,主干分支,有时候修改代码量过大,页面因为文件限制无法完成合并操作,可以通过命令行修改:
# 从远端新拉分支
git pull
# 切换到源分支
git checkout git-merge-test
# 拉取新分支,git-merge-test02为新分支名
git checkout -b git-merge-test02
# 推送到远端
git push origin git-merge-test02
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To http://gitlab.com/xxx/yyy.git
* [new branch] git-merge-test02 -> git-merge-test02
# 从远端更新,显示没有关联本地
git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> git-merge-test01
# 执行
git branch --set-upstream-to=origin/git-merge-test git-merge-test02
# 再次更新,正常
git pull
Already up to date.
# 更改git-merge-test02 内容并提交远程
# 切换到源分支
git checkout git-merge-test
# git merge
git merge git-merge-test02
Updating e8751f9..15bbef2
Fast-forward
version-management.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
# 提交远程
git push origin git-merge-test
三、参考文档
1、https://blog.csdn.net/shujuliu818/article/details/121041349
2、https://blog.csdn.net/hello_1995/article/details/119865172
3、https://blog.csdn.net/zl1zl2zl3/article/details/94019526
4、https://www.yiibai.com/git/git_merge.html