iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >git中包含多个分支和合并实现的实例分析
  • 538
分享到

git中包含多个分支和合并实现的实例分析

2023-06-28 15:06:43 538人浏览 薄情痞子
摘要

git中包含多个分支和合并实现的实例分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。下面和大家讲解一下git的使用。一、包含多个分支和合并实现的实例出现合并冲突的实例[roo

git中包含多个分支和合并实现的实例分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

下面和大家讲解一下git的使用。

一、包含多个分支和合并实现的实例

出现合并冲突的实例

[root@localhost ~]# mkdir -p /git/branche[root@localhost branche]# cp -rv ../wanyan/* .   //偷懒一下`../wanyan/README’ -> `./README’`../wanyan/lib’ -> `./lib’`../wanyan/lib/comment’ -> `./lib/comment’`../wanyan/lib/include’ -> `./lib/include’`../wanyan/lib/include/comment’ -> `./lib/include/comment’`../wanyan/lib/include/main.c’ -> `./lib/include/main.c’`../wanyan/lib/README’ -> `./lib/README’[root@localhost branche]# git initInitialized empty Git repository in /git/branche/.git/[root@localhost branche]# git add .[root@localhost branche]# git commit -m “1st commit”[master (root-commit) e9f37b6] 1st commit5 files changed, 9 insertions(+), 0 deletions(-)create mode 100644 READMEcreate mode 100644 lib/READMEcreate mode 100644 lib/commentcreate mode 100644 lib/include/commentcreate mode 100644 lib/include/main.c[root@localhost branche]# cat .git/HEADref: refs/heads/master[root@localhost branche]# cat .git/refs/heads/mastere9f37b62445a7c855108cb00455c9922ea356c29[root@localhost branche]# git cat-file -t e9f3Commit

第一次改变:

[root@localhost branche]# vi lib/comment includechangethe last change[root@localhost branche]# git commit -a -m “2rd commit”[master c2a876e] 2rd commit1 files changed, 1 insertions(+), 0 deletions(-)

第二次改变:

[root@localhost branche]# vi README just test!another hang!last hang[root@localhost branche]# git commit -a -m “3rd commit”[master f5febf9] 3rd commit1 files changed, 1 insertions(+), 0 deletions(-)

创建分支

[root@localhost branche]# git branch laji[root@localhost branche]# ll .git/refs/heads/total 16-rw-r–r– 1 root root 41 Nov 27 05:19 laji-rw-r–r– 1 root root 41 Nov 27 05:18 master[root@localhost branche]# cat .git/refs/heads/laji  //以下可以看出指向同一个commitf5febf9e98c5dc2a1279a56c47642677fdea79ec[root@localhost branche]# cat .git/refs/heads/masterf5febf9e98c5dc2a1279a56c47642677fdea79ec[root@localhost branche]# git branch  //查看当前使用的分支laji* master[root@localhost branche]# git checkout laji  //分支的切换Switched to branch ‘laji’[root@localhost branche]# git branch* lajimaster[root@localhost branche]# cat .git/HEADref: refs/heads/laji

接下来演示的是分支之间的关系(互不影响),在分支laji下的修改对master分支没任何影响。

首先是在laji分支的下的修改

[root@localhost branche]# vi READMEjust test!another hang!last hanGChange for branch[root@localhost branche]# git  commit -a -m “laji 4th commit”[laji b72a123] laji 4th commit1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost branche]# cat READMEjust test!another hang!last hangchange for branch[root@localhost branche]# cat .git/refs/heads/laji  //commit不相同了,可见出现了分支b72a1238f9962dd103c5839077026e7c342595ce[root@localhost branche]# cat .git/refs/heads/masterf5febf9e98c5dc2a1279a56c47642677fdea79ec

然后切换到master分支观察下

[root@localhost branche]# git checkout masterSwitched to branch ‘master’[root@localhost branche]# git branchlaji* master[root@localhost branche]# cat READMEjust test!another hang!last hang接着创造分叉(就是对mater下做出进一步的git)[root@localhost branche]# git branchlaji* master[root@localhost branche]# vi README just test!another hang!last hangThe master change[root@localhost branche]# git commit -a -m “master 4th commit”[master bf7bf97] master 4th commit1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost branche]# cat README   //列出和laji分支做对比just test!another hang!last hangThe master change[root@localhost branche]# git checkout lajiSwitched to branch ‘laji’[root@localhost branche]# cat READMEjust test!another hang!last hangchange for branch

最后就是分支的合并(把laji 合并到master),这个合并可以是不同的文件之间的合并(因为合作开发项目时,所做的工作基本是很难相同的)

[root@localhost branche]# git branchlaji* master[root@localhost branche]# git merge lajiAuto-merging READMECONFLICT (content): Merge conflict in READMEAutomatic merge failed; fix conflicts and then commit the result.[root@localhost branche]# cat README  //因为是同一个文件的合并出现了冲突just test!another hang!last hangThe master change=======change for branch>>>>>>> laji[root@localhost branche]# git branchlaji*master[root@localhost branche]# vi README just test!another hang!last hangThe master changechange for branch~[root@localhost branche]# git add .[root@localhost branche]# git commit “last commit”这样就可以了,解决了冲突,提交成功。[root@localhost branche]# git branch -D laji  //删除没用的分支Deleted branch laji (was b72a123).

不出现冲突的实例

[root@localhost other]# cd ..[root@localhost git]# mkdir another[root@localhost git]# cd another/[root@localhost another]# vi a1 wanyan~[root@localhost another]# vi a2 ethnicity[root@localhost another]# git initInitialized empty Git repository in /git/another/.git/[root@localhost another]# git add .[root@localhost another]# git commit -m “1st commit”[master (root-commit) f723f47] 1st commit2 files changed, 2 insertions(+), 0 deletions(-)create mode 100644 a1create mode 100644 a2[root@localhost another]# git branch laji[root@localhost another]# git branchlaji* master[root@localhost another]# git checkout lajiSwitched to branch ‘laji’[root@localhost another]# vi a1 wanyanzhengjing[root@localhost another]# git commit -a -m “laji 2nd commit”[laji 05cda63] laji 2nd commit1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost another]# git checkout master[root@localhost another]# vi a2 ethnicitybeta[root@localhost another]# git commit -a -m “mater 3rd commit”[master 1239b8e] mater 3rd commit1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost another]# cat a1wanyan[root@localhost another]# cat a2ethnicitybeta[root@localhost another]# git checkout lajiSwitched to branch ‘laji’[root@localhost another]# cat a1wanyanzhengjing[root@localhost another]# cat a2ethnicity[root@localhost another]# git checkout masterSwitched to branch ‘master’[root@localhost another]# git merge lajiMerge made by the ‘recursive’ strategy.a1 |    1 +1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost another]# cat a1wanyanzhengjing[root@localhost another]# cat a2ethnicitybeta[root@localhost another]# git branch -D laji   //删除分支Deleted branch laji (was 05cda63).[root@localhost another]# git branch* master

二、仅有一个分支的合并实例

[root@localhost git]# mkdir other[root@localhost git]# cd other/[root@localhost other]# vim mainhello ethnicitybeta[root@localhost other]# git initInitialized empty Git repository in /git/other/.git/[root@localhost other]# git add .[root@localhost other]# git commit -m ‘1st commit’[master (root-commit) 9ef10c3] 1st commit1 files changed, 1 insertions(+), 0 deletions(-)create mode 100644 main[root@localhost other]# git branch wanyan[root@localhost other]# git checkout wanyanSwitched to branch ‘wanyan’[root@localhost other]# git branchmaster*wanyan[root@localhost other]# vi main hello ethnicitybetawanyanzhenjiang~[root@localhost other]# git commit -a -m “wanyan 2nd commit”[wanyan 96aa677] wanyan 2nd commit1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost other]# cat mainhello ethnicitybetawanyanzhenjiang[root@localhost other]# git checkout masterSwitched to branch ‘master’[root@localhost other]# git branch* masterwanyan[root@localhost other]# cat mainhello ethnicitybeta[root@localhost other]# git checkout masterSwitched to branch ‘master’[root@localhost other]# git merge wanyanUpdating 9ef10c3..96aa677Fast-forward    //表示被合并的分支并没有出现分叉main |    1 +1 files changed, 1 insertions(+), 0 deletions(-)[root@localhost other]# cat mainhello ethnicitybetawanyanzhenjiang

看完上述内容,你们掌握git中包含多个分支和合并实现的实例分析的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注编程网精选频道,感谢各位的阅读!

--结束END--

本文标题: git中包含多个分支和合并实现的实例分析

本文链接: https://www.lsjlt.com/news/320524.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • git中包含多个分支和合并实现的实例分析
    git中包含多个分支和合并实现的实例分析,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。下面和大家讲解一下git的使用。一、包含多个分支和合并实现的实例出现合并冲突的实例[roo...
    99+
    2023-06-28
  • git的分支与和并实例分析
    这篇文章主要介绍“git的分支与和并实例分析”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“git的分支与和并实例分析”文章能帮助大家解决问题。一旦某分支有了独立内容,你终究会希望将它合并回到你的主分...
    99+
    2023-06-28
  • idea中使用git合并分支实践
    目录idea使用git合并分支idea操作git时,合并分支+解决冲突总结1、IDEA使用Git合并到Master分支&冲突解决步骤总结2、idea操作git时合并分支及解决...
    99+
    2023-03-01
    idea git git合并分支 使用git合并分支
  • Git高级合并方法实例分析
    本篇内容介绍了“Git高级合并方法实例分析”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!高级合并在 Git 中合并是相当容易的。 因为 Gi...
    99+
    2023-06-29
  • git中删除分支和回滚的示例分析
    小编给大家分享一下git中删除分支和回滚的示例分析,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!git 删除分支和回滚的实例详解【git 删除本地分支】git&n...
    99+
    2023-06-09
  • Git 中的 PHP 接口和 JavaScript:如何处理分支合并?
    Git 是一个流行的版本控制系统,被广泛用于软件开发中。PHP 和 JavaScript 是两种常用的编程语言,它们在 Git 中的使用也是非常普遍的。本文将介绍 Git 中的 PHP 接口和 JavaScript 如何处理分支合并。 一、...
    99+
    2023-06-30
    接口 javascript git
  • mybatis分割字符串并循环实现in多个参数的示例分析
    这篇文章主要为大家展示了“mybatis分割字符串并循环实现in多个参数的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“mybatis分割字符串并循环实现in多个参数的示例分析”这篇文章...
    99+
    2023-06-15
  • pandas中DataFrame数据合并连接的实例分析
    这篇文章主要介绍了pandas中DataFrame数据合并连接的实例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。pandas作者Wes McKinney 在【PYTHO...
    99+
    2023-06-15
  • SQL字符串的合并与拆分实例代码分析
    本篇内容主要讲解“SQL字符串的合并与拆分实例代码分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SQL字符串的合并与拆分实例代码分析”吧!字符串的合并在Or...
    99+
    2024-04-02
  • Entity Framework实体拆分多个表的示例分析
    这篇文章主要为大家展示了“Entity Framework实体拆分多个表的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Entity Framework实体拆分多个表...
    99+
    2023-06-29
  • Node.js中的多进程和多线程实例分析
    本篇内容主要讲解“Node.js中的多进程和多线程实例分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Node.js中的多进程和多线程实例分析”吧!我们都知道...
    99+
    2024-04-02
  • C#实现文件分割和合并的示例详解
    目录实践过程效果代码实践过程 效果 代码 public partial class frmSplit : Form { public frmSplit() { ...
    99+
    2022-12-26
    C#文件分割 合并 C#文件分割 C#文件合并
  • Java实现合并多个PDF的示例代码
    这里合并用到了一个itext的包。使用maven直接导入依赖即可。 <dependency> <groupId>com.lowagie</gro...
    99+
    2024-04-02
  • Entity Framework表拆分为多个实体的示例分析
    小编给大家分享一下Entity Framework表拆分为多个实体的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!概念表拆分:一个表拆分成多个实体,例如Photograph表,可以拆分为Photograp...
    99+
    2023-06-29
  • Java 并发包中的读写锁及其实现分析
    这期内容当中小编将会给大家带来有关Java 并发包中的读写锁及其实现分析,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1. 前言在Java并发包中常用的锁(如:ReentrantLock),基本上都是排他...
    99+
    2023-06-17
  • MySQL中多实例配置和管理的示例分析
    这篇文章主要介绍MySQL中多实例配置和管理的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完! mysql的多实例有两种方式可以实现,两种方式各有...
    99+
    2024-04-02
  • Mysql实现合并多个分组(GROUP_CONCAT及其平替函数)
    目录1. mysql 中的 GROUP_CONCAT 函数1.1 GROUP_CONCAT 函数1.2 CONCAT_WS 函数2. 功能类似的方法2.1 CONCAT 函数2.2 GROUP_CONCAT 和 CONC...
    99+
    2023-10-11
    Mysql 合并多个分组 Mysql GROUP_CONCAT
  • Go语言中的闭包实例分析
    这篇文章主要介绍“Go语言中的闭包实例分析”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Go语言中的闭包实例分析”文章能帮助大家解决问题。一、函数的变量作用域和可见性全局变量在main函数执行之前初...
    99+
    2023-07-02
  • JavaScript中合并和克隆对象的示例分析
    小编给大家分享一下JavaScript中合并和克隆对象的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!当我们想要复制原始值和引用值(对象)时,它们的行为会大不相同。原始值我们假设一个变量 name 具有一个与之关联...
    99+
    2023-06-15
  • MapReduce多种join实现的示例分析
    这篇文章将为大家详细讲解有关MapReduce多种join实现的示例分析,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。一、概述   对于RDBMS中的join操...
    99+
    2023-06-03
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作