git 创建、合并、删除分支
-
创建分支:
git branch <name>
-
查看分支:
git branch
-
切换分支:
git checkout <name>
-
创建并切换分支:
git checkout -b <name>
-
合并某分支到当前分支:
git merge <name>
-
删除分支:
git branch -d <name>
代码说明
创建一个 new
分支
$ git branch new
查看分支 *
指的是当前分支
$ git branch
* master
new
切换分支到 new
分支
$ git checkout new
Switched to branch 'new'
查看当前分支 为new
了
$ git branch
master
* new
s#################################
为了说明分支合并 在git的仓库文件夹处创建一个demo.txt
文件,文件里面内容11111111
然后提交到工作区
$ git add demo.txt
$ git commit -m demo.txt
[new 6f492b7] demo.txt
1 file changed, 1 insertion(+)
create mode 100644 demo.txt
合并分支,先切换到master分支
$ git checkout master
Switched to branch 'master'
D no
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
再合并分支
$ git merge new
Updating be49bcb..6f492b7
Fast-forward
demo.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 demo.txt
使用cat
查看
可以看见demo.txt
确实到了master
中
$ cat demo.txt
11111111