在这个第四个文章中,我将练习GIT的高级阶段了,由于高级阶段的内容转的比较多,我自己的代码除了我自己可以看懂意外,大家可能看不懂,所以我将会按照

http://git.wiki.navisec.it/stepup/stepup2_1.html这里教程里面的内容进行一次截图演示

按照教程,我讲先新建一个文件夹,作为本地数据库

  1. $ mkdir tutorial
  2. $ cd tutorial
  3. $ git init

本地数据初始化完毕

下一步就是新建一个文件

剩下步骤就是吧这个文件添加到git的索引下,并且提交

下一步就是建立分支

按照教程来

  1. $ git branch issue1
  2. $ git branch


下一步,切换分支

  1. $ git branch issue1
  2. $ git branch
  1. $ git checkout issue1

下一步合并分支

删除分支

下面是最重要的了,就是两个人同时开发的时候,在合并分支的时候,出现合并冲突怎么解决了

和前面的差不多了

现在在issue2中编辑文件,切换到issue3中编辑文件

下面就是切换到 master分支下合并文件

可以看到,我们可以顺利合并issue2,但是在合并issue3的时候提示内容冲突

这里我们只需要打开文件,手动除了一下冲突就好

完成合并

还有一种合并方式,这里实践一下

还原issue3的合并

切换到issue3下面

合并的时候,会发现有冲突

下面直接打开就好

下面贴上我的所有操作记录

  1. dreamlife@Ubuntu:~$ mkdir tutorial
  2. dreamlife@Ubuntu:~$ cd tutorial
  3. dreamlife@Ubuntu:~/tutorial$ git init
  4. 初始化空的 Git 仓库于 /home/dreamlife/tutorial/.git/
  5. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  6. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  7. dreamlife@Ubuntu:~/tutorial$
  8. dreamlife@Ubuntu:~/tutorial$
  9. dreamlife@Ubuntu:~/tutorial$
  10. dreamlife@Ubuntu:~/tutorial$ git add myfile.txt
  11. dreamlife@Ubuntu:~/tutorial$ git commit -m"firs commit"
  12. [master (根提交) 124808a] firs commit
  13. 1 file changed, 1 insertion(+)
  14. create mode 100644 myfile.txt
  15. dreamlife@Ubuntu:~/tutorial$ git status
  16. 位于分支 master
  17. 无文件要提交,干净的工作区
  18. dreamlife@Ubuntu:~/tutorial$ git log
  19. commit 124808ac46c33bd91f5c3c7b7f9327f71c01f80e
  20. Author: DreamLife <dream_dag@163.com>
  21. Date: Sun Sep 11 13:45:49 2016 +0800
  22.  
  23. firs commit
  24. dreamlife@Ubuntu:~/tutorial$ git branch issue1
  25. dreamlife@Ubuntu:~/tutorial$ git branch
  26. issue1
  27. * master
  28. dreamlife@Ubuntu:~/tutorial$ git checkout issue1
  29. 切换到分支 'issue1'
  30. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  31. dreamlife@Ubuntu:~/tutorial$ git add myfile.txt
  32. dreamlife@Ubuntu:~/tutorial$ git commit -m"添加add的说明"
  33. [issue1 0151f5d] 添加add的说明
  34. 1 file changed, 2 insertions(+)
  35. dreamlife@Ubuntu:~/tutorial$ git status
  36. 位于分支 issue1
  37. 无文件要提交,干净的工作区
  38. dreamlife@Ubuntu:~/tutorial$ git log
  39. commit 0151f5d61c0cb286bbd40f70446df6a8d18e91de
  40. Author: DreamLife <dream_dag@163.com>
  41. Date: Sun Sep 11 13:52:07 2016 +0800
  42.  
  43. 添加add的说明
  44.  
  45. commit 124808ac46c33bd91f5c3c7b7f9327f71c01f80e
  46. Author: DreamLife <dream_dag@163.com>
  47. Date: Sun Sep 11 13:45:49 2016 +0800
  48.  
  49. firs commit
  50. dreamlife@Ubuntu:~/tutorial$ git checkout master
  51. 切换到分支 'master'
  52. dreamlife@Ubuntu:~/tutorial$ git merge issue1
  53. 更新 124808a..0151f5d
  54. Fast-forward
  55. myfile.txt | 2 ++
  56. 1 file changed, 2 insertions(+)
  57. dreamlife@Ubuntu:~/tutorial$ git status
  58. 位于分支 master
  59. 无文件要提交,干净的工作区
  60. dreamlife@Ubuntu:~/tutorial$ git log
  61. commit 0151f5d61c0cb286bbd40f70446df6a8d18e91de
  62. Author: DreamLife <dream_dag@163.com>
  63. Date: Sun Sep 11 13:52:07 2016 +0800
  64.  
  65. 添加add的说明
  66.  
  67. commit 124808ac46c33bd91f5c3c7b7f9327f71c01f80e
  68. Author: DreamLife <dream_dag@163.com>
  69. Date: Sun Sep 11 13:45:49 2016 +0800
  70.  
  71. firs commit
  72. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  73. dreamlife@Ubuntu:~/tutorial$ git branch -d issue1
  74. 已删除分支 issue1(曾为 0151f5d)。
  75. dreamlife@Ubuntu:~/tutorial$ git branch
  76. * master
  77. dreamlife@Ubuntu:~/tutorial$ git branch issue2
  78. dreamlife@Ubuntu:~/tutorial$ git branch issue3
  79. dreamlife@Ubuntu:~/tutorial$ git checkout issue2
  80. 切换到分支 'issue2'
  81. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  82. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  83. dreamlife@Ubuntu:~/tutorial$ git add myfile.txt
  84. dreamlife@Ubuntu:~/tutorial$ git commit -m "添加commit说明"
  85. [issue2 ca3b9a4] 添加commit说明
  86. 1 file changed, 2 insertions(+)
  87. dreamlife@Ubuntu:~/tutorial$ git checkout issue3
  88. 切换到分支 'issue3'
  89. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  90. dreamlife@Ubuntu:~/tutorial$ git add myfile.txt
  91. dreamlife@Ubuntu:~/tutorial$ git commit -m "添加pull的说明"
  92. [issue3 6f118ad] 添加pull的说明
  93. 1 file changed, 2 insertions(+)
  94. dreamlife@Ubuntu:~/tutorial$ git checkout master
  95. 切换到分支 'master'
  96. dreamlife@Ubuntu:~/tutorial$ git merge issue2
  97. 更新 0151f5d..ca3b9a4
  98. Fast-forward
  99. myfile.txt | 2 ++
  100. 1 file changed, 2 insertions(+)
  101. dreamlife@Ubuntu:~/tutorial$ git merge issue3
  102. 自动合并 myfile.txt
  103. 冲突(内容):合并冲突于 myfile.txt
  104. 自动合并失败,修正冲突然后提交修正的结果。
  105. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  106. dreamlife@Ubuntu:~/tutorial$ git add myfile.txt
  107. dreamlife@Ubuntu:~/tutorial$ git commit -m "合并issue3分支"
  108. [master c42c43a] 合并issue3分支
  109. dreamlife@Ubuntu:~/tutorial$ git reset --hard HEAD`
  110. > ^C
  111. dreamlife@Ubuntu:~/tutorial$ git reset --hard HEAD~
  112. HEAD 现在位于 ca3b9a4 添加commit说明
  113. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  114. dreamlife@Ubuntu:~/tutorial$ git che
  115. checkout cherry cherry-pick
  116. dreamlife@Ubuntu:~/tutorial$ git checkout issue3
  117. 切换到分支 'issue3'
  118. dreamlife@Ubuntu:~/tutorial$ git rebase master
  119. 首先,回退分支以便在上面重放您的工作...
  120. 应用:添加pull的说明
  121. 使用索引来重建一个(三方合并的)基础目录树...
  122. M myfile.txt
  123. 回落到基础版本上打补丁及进行三方合并...
  124. 自动合并 myfile.txt
  125. 冲突(内容):合并冲突于 myfile.txt
  126. error: 无法合并变更。
  127. 打补丁失败于 0001 添加pull的说明
  128. 失败的补丁文件副本位于:.git/rebase-apply/patch
  129.  
  130. 当您解决了此问题后,执行 "git rebase --continue"。
  131. 如果您想跳过此补丁,则执行 "git rebase --skip"。
  132. 要恢复原分支并停止变基,执行 "git rebase --abort"。
  133.  
  134. dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt
  135. dreamlife@Ubuntu:~/tutorial$ git add myfile.txt
  136. dreamlife@Ubuntu:~/tutorial$ git rebase --continue
  137. 应用:添加pull的说明
  138. dreamlife@Ubuntu:~/tutorial$ git checkout master
  139. 切换到分支 'master'
  140. dreamlife@Ubuntu:~/tutorial$ git merge issue3
  141. 更新 ca3b9a4..15c5986
  142. Fast-forward
  143. myfile.txt | 4 ++++
  144. 1 file changed, 4 insertions(+)
  145. dreamlife@Ubuntu:~/tutorial$
  146. dreamlife@Ubuntu:~/tutorial$

在合并冲突这个地方,我联系了好多次,大家也可以多联系几次,这里还是希望大家看下链接中内容,真的写的很好

http://git.wiki.navisec.it/stepup/stepup2_8.html

Ubuntu下使用Git_4的更多相关文章

  1. 在Ubuntu下搭建ASP.NET 5开发环境

    在Ubuntu下搭建ASP.NET 5开发环境 0x00 写在前面的废话 年底这段时间实在太忙了,各种事情都凑在这个时候,没时间去学习自己感兴趣的东西,所以博客也好就没写了.最近工作上有个小功能要做成 ...

  2. 在Ubuntu下搭建Spark群集

    在前一篇文章中,我们已经搭建好了Hadoop的群集,接下来,我们就是需要基于这个Hadoop群集,搭建Spark的群集.由于前面已经做了大量的工作,所以接下来搭建Spark会简单很多. 首先打开三个虚 ...

  3. Ubuntu下开启php调试模式,显示报错信息

    在Ubuntu下php的缺省设置是不显示错误信息的,如果程序出错会显示“无法处理此请求的错误提示”,这在开发环境下非常不方便. 其实我们只要编辑下apache的配置文件就好 1.我的apache 配置 ...

  4. 在Ubuntu下安装ovs-dpdk

    在Ubuntu下安装ovs-dpdk 参考资料:https://software.intel.com/zh-cn/articles/using-open-vswitch-with-dpdk-on-ub ...

  5. Ubuntu 下安装QT

    Ubuntu 下安装QT 本文使用的环境 QT Library: qt-everywhere-opensource-src-4.7.4.tar.gz QT Creator: qt-creator-li ...

  6. Torch7在Ubuntu下的安装与配置

    Torch7的本系列教程的主要目的是介绍Torch的入门使用.今天首先分享一下Torch7的安装.(在Ubuntu14.04安装torch7) 为什么选择Torch Torch的目标是在建立科学算法的 ...

  7. Ubuntu 下ibus拼音输入法启用 (ubuntu 16.04

    Ubuntu 下ibus拼音输入法启用 我安装的是英文版的ubuntu 16.04,打开只带英文,并没有中文. 设置输入法为iBus 从system settings 进入language suppo ...

  8. Ubuntu下git的安装与使用

    Ubuntu下git的安装与使用 Ubuntu下git的安装与使用与Windows下的大致相同,只不过个人感觉在Ubuntu下使用git更方便. 首先,确认你的系统是否已安装git,可以通过git指令 ...

  9. 在ubuntu下安装google chrome

    由于手上有两台电脑,再加上我那个选择困难症加上纠结劲.所以果断把其中一台电脑只装linux系统,另一台电脑只装windows了.免得我老纠结!于是linux便选择了ubuntu. 由于浏览器一直用的是 ...

随机推荐

  1. FMDB初步使用小结

    频繁的网络请求会给用户不好的体验,在最近开发的一个项目中有一个获取个人详细信息的界面,由于是子页面,进入页面后需要重新加载数据并刷新页面,而,每一次请求服务器再返回数据不仅用户体验不好,也花费手机流量 ...

  2. 一组div跟随鼠标移动,反应鼠标轨迹

    <!DOCTYPE html> <html> <head> <title>div随鼠标移动</title> <style type=& ...

  3. Windows XP和Wndows7误删除了注册表下.exe文件夹之修复办法

    在桌面空白处鼠标右击选择“新建-文本文档”,然后将下面的代码复制粘贴进去;如图所示: Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\. ...

  4. C# .Net Framework4.5中配置和使用managedCUDA及常见问题解决办法

    主要参考英文帖子.我就不翻译了哈.很容易懂的. 先说明我的运行平台: 1.IDE:Visual Studio 2012 C# .Net Framework4.5,使用默认安装路径: 2.显卡类型:NV ...

  5. Android学习笔记_26_多媒体之拍照

    一.配置文件: 需要引入摄像头权限,sdcard读写权限. <?xml version="1.0" encoding="utf-8"?> <m ...

  6. Django-rest-framework(一)简单入门使用

    简单的使用 Django-rest-framework 建成DRF,可以帮助我们快速构建出 django的rest full 风格的api接口. 其源码容易理解,所以我们可以很方便的使用. 安装 pi ...

  7. Oracle system 忘记密码,怎么修改密码

    1.win键+R键,输入cmd,打开命令提示符.(小黑窗) 2.输入:sqlplus /nolog 3.输入conn /as sysdba(以超级管理员身份登录 4.输入alter user syst ...

  8. HTML简介及基本标记

    HTML简介 HTML是Hypertext Markup Language的英文缩写,即超文本标记语言 使用 HTML 语言可以: 控制页面和内容的外观 插入的链接检索联机信息 创建表单,收集用户的信 ...

  9. MVVM、MVC框架的认识

    推荐博客: https://blog.csdn.net/jia12216/article/details/55520426 https://www.cnblogs.com/sunny_z/p/7093 ...

  10. LeetCode 中级 - 翻转矩阵后的得分(861)

    有一个二维矩阵 A 其中每个元素的值为 0 或 1 . 移动是指选择任一行或列,并转换该行或列中的每一个值:将所有 0 都更改为 1,将所有 1 都更改为 0. 在做出任意次数的移动后,将该矩阵的每一 ...