zl程序教程

您现在的位置是:首页 >  工具

当前栏目

【Git】Git 分支管理 ( 解决分支合并冲突 | 创建并切换分支 git switch -c feature1 | 修改 feature1 分支并提交 | 修改 master 主版本并提交 )

Git 解决 管理 版本 创建 修改 分支 切换
2023-06-13 09:18:00 时间

文章目录

一、创建并切换分支 git switch -c feature1


执行

git switch -c feature1

命令 , 创建分支 feature1 , 并切换到该分支 ;

执行过程 :

D:\Git\git-learning-course>git switch -c feature1
Switched to a new branch 'feature1'

D:\Git\git-learning-course>

二、修改 feature1 分支并提交


修改 feature1 中的 README.txt 文件内容为 feature1 , 并执行 git add README.txtgit commit -m "feature1" 命令提交到版本库 ;

执行过程 :

D:\Git\git-learning-course>git switch -c feature1
Switched to a new branch 'feature1'

D:\Git\git-learning-course>git add README.txt

D:\Git\git-learning-course>git commit -m "feature1"
[feature1 26b1978] feature1
 1 file changed, 1 insertion(+), 1 deletion(-)

三、修改 master 主版本并提交


修改 master 中的 README.txt 文件内容为 master , 并执行 git add README.txtgit commit -m "feature1" 命令提交到版本库 ;

执行过程 :

D:\Git\git-learning-course>git switch master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

D:\Git\git-learning-course>git add README.txt

D:\Git\git-learning-course>git commit -m "master"
[master c9842ef] master
 1 file changed, 1 insertion(+), 1 deletion(-)

D:\Git\git-learning-course>git branch
  feature1
* master

上述操作的目的是 , 在 master 分支中修改 README.txt 文件 , 在 feature1 分支中修改 README.txt 文件 , 两个分支中的相同文件内容不同 , 必然会导致冲突产生 ;