查看分支
git branch
远程分支
git branch -r
创建分支
git branch 名称
切换分支
git checkout 分支名
删除分支
需切换到其他分支后再删除
git branch -D 分支名 #大写d不提示,直接删除 git branch -d #小写d提示处理合并后才能删除
分支合并
fast forward合并
主分支没变,其他分支commit后合并进主分支,实际上把master的指针从c2移动到了c3
在master分支上执行
git merge bugfix
合并后
3 way merge合并
主分支和其他分支都有过commit。
在master分支上执行
git merge bugfix
会提示编辑commit
输入 :wq 保存
合并后
解决冲突:
如果c4和c3同时修改了同一个文件
合并时会提示失败,需要修改test文件,因为两个分支都修改过
文件状态处于
使用vscode修改文件
选择一种方式修改文件,然后重新 add commit
提交时会出现
:wa 保存
解决使用fast forward会造成隐藏分支的问题
git rebase master
如果有多人合作不推荐使用git rebase