windows下git的安装、配置与操作(七)——分支创建于合并的操作演示

本文详细介绍了使用Git进行分支管理的基本操作,包括创建、切换分支和合并分支的方法,并通过实际代码示例展示了如何操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先创建并且切换分支到dev:

$ git checkout -b dev
Switched to a new branch 'dev'
查看当前分支状态:

$ git branch
* dev
  master
当前文件内容:

<pre name="code" class="plain">$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!


我们修改文件内容:

$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
Creating a new branch is quick.
然后添加并提交:

$ git add readme.txt
$ git commit -m "branch dev modify"
[dev ecf03eb] branch dev modify
 1 file changed, 1 insertion(+)
然后切换回master主分支:

$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)
这时候我们的文件的内容:

$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
dev修改的内容并没有体现在master分支上去。

合并分支dev到master分支上去:

$ git merge dev
Updating dc7f36c..ecf03eb
Fast-forward
 readme.txt | 1 +
 1 file changed, 1 insertion(+)
在查看文件内容:

$ cat readme.txt
Hello World!
this is a git file.
this file will commit to git.
we are young!yes we are young!
Creating a new branch is quick.
修改成功。
由两个图可以很清晰的看到这个过程(git gui):

最后可以删除分支:

$ git branch -d dev
Deleted branch dev (was ecf03eb).

ZhangLei@ZHANGLEI-PC /d/GitRepository/myapp1 (master)
$ git branch
* master


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值