当前位置: 首页> 财经> 产业 > Git分支管理

Git分支管理

时间:2025/7/9 21:26:18来源:https://blog.csdn.net/u012273398/article/details/139833381 浏览次数:0次

创建分支命令:

git branch (branchname)

切换分支命令:

git checkout (branchname)

合并分支命令

git merge 

创建一个测试目录:

$ mkdir gitdemo
$ cd gitdemo/
$ git init
Initialized empty Git repository...
$ touch README
$ git add README
$ git commit -m '第一次版本提交'
[master (root-commit) 3b58100] 第一次版本提交1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 README

列出分支

git branch

创建分支。

$ git branch testing
$ git branch
* mastertesting

 git checkout -b (branchname) 创建新分支并切换分支。

$ git checkout -b newtest
Switched to a new branch 'newtest'
$ git rm test.txt 
rm 'test.txt'
$ ls
README
$ touch runoob.php
$ git add .
$ git commit -am 'removed test.txt、add runoob.php'
[newtest c1501a2] removed test.txt、add runoob.php2 files changed, 1 deletion(-)create mode 100644 runoob.phpdelete mode 100644 test.txt
$ ls
README        runoob.php
$ git checkout master
Switched to branch 'master'
$ ls
README        test.txt

删除分支

git branch -d (branchname)

分支合并

git merge

合并冲突

$ git merge change_site
Auto-merging runoob.php
CONFLICT (content): Merge conflict in runoob.php
Automatic merge failed; fix conflicts and then commit the result.$ cat runoob.php     # 打开文件,看到冲突内容
<?php
<<<<<<< HEAD
echo 1;
=======
echo 'runoob';
>>>>>>> change_site
?>

手动修改

$ vim runoob.php 
$ cat runoob.php
<?php
echo 1;
echo 'runoob';
?>
$ git diff
diff --cc runoob.php
index ac60739,b63d7d7..0000000
--- a/runoob.php
+++ b/runoob.php
@@@ -1,3 -1,3 +1,4 @@@<?php+echo 1;
+ echo 'runoob';?>

用 git add 告诉 冲突已解决

$ git status -s
UU runoob.php
$ git add runoob.php
$ git status -s
M  runoob.php
$ git commit
[master 88afe0e] Merge branch 'change_site'

成功解决合并冲突,并提交。

关键字:Git分支管理

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: