Ubuntu下使用Git_4

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

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

image.png

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

image.png

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

image.png

下一步就是建立分支

image.png

按照教程来

image.png

下一步,切换分支

image.png

image.png

下一步合并分支

image.png

image.png

删除分支

image.png

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

 

和前面的差不多了

image.png

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

 

 

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

image.png

完成合并

 

 

 

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

还原issue3的合并

image.png

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

下面直接打开就好

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

 

dreamlife@Ubuntu:~$ mkdir tutorial

dreamlife@Ubuntu:~$ cd tutorial

dreamlife@Ubuntu:~/tutorial$ git init

初始化空的 Git 仓库于 /home/dreamlife/tutorial/.git/

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$

dreamlife@Ubuntu:~/tutorial$

dreamlife@Ubuntu:~/tutorial$

dreamlife@Ubuntu:~/tutorial$ git add myfile.txt

dreamlife@Ubuntu:~/tutorial$ git commit -m"firs commit"

[master (根提交) 124808a] firs commit

1 file changed, 1 insertion(+)

create mode 100644 myfile.txt

dreamlife@Ubuntu:~/tutorial$ git status

位于分支 master

无文件要提交,干净的工作区

dreamlife@Ubuntu:~/tutorial$ git log

commit 124808ac46c33bd91f5c3c7b7f9327f71c01f80e

Author: DreamLife

Date:   Sun Sep 11 13:45:49 2016 +0800


   firs commit

dreamlife@Ubuntu:~/tutorial$ git branch issue1

dreamlife@Ubuntu:~/tutorial$ git branch

 issue1

* master

dreamlife@Ubuntu:~/tutorial$ git checkout issue1

切换到分支 'issue1'

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git add myfile.txt

dreamlife@Ubuntu:~/tutorial$ git commit -m"添加add的说明"

[issue1 0151f5d] 添加add的说明

1 file changed, 2 insertions(+)

dreamlife@Ubuntu:~/tutorial$ git status

位于分支 issue1

无文件要提交,干净的工作区

dreamlife@Ubuntu:~/tutorial$ git log

commit 0151f5d61c0cb286bbd40f70446df6a8d18e91de

Author: DreamLife

Date:   Sun Sep 11 13:52:07 2016 +0800


   添加add的说明


commit 124808ac46c33bd91f5c3c7b7f9327f71c01f80e

Author: DreamLife

Date:   Sun Sep 11 13:45:49 2016 +0800


   firs commit

dreamlife@Ubuntu:~/tutorial$ git checkout master

切换到分支 'master'

dreamlife@Ubuntu:~/tutorial$ git merge issue1

更新 124808a..0151f5d

Fast-forward

myfile.txt | 2 ++

1 file changed, 2 insertions(+)

dreamlife@Ubuntu:~/tutorial$ git status

位于分支 master

无文件要提交,干净的工作区

dreamlife@Ubuntu:~/tutorial$ git log

commit 0151f5d61c0cb286bbd40f70446df6a8d18e91de

Author: DreamLife

Date:   Sun Sep 11 13:52:07 2016 +0800


   添加add的说明


commit 124808ac46c33bd91f5c3c7b7f9327f71c01f80e

Author: DreamLife

Date:   Sun Sep 11 13:45:49 2016 +0800


   firs commit

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git  branch -d issue1

已删除分支 issue1(曾为 0151f5d)。

dreamlife@Ubuntu:~/tutorial$ git branch

* master

dreamlife@Ubuntu:~/tutorial$ git branch issue2

dreamlife@Ubuntu:~/tutorial$ git branch issue3

dreamlife@Ubuntu:~/tutorial$ git checkout issue2

切换到分支 'issue2'

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git add myfile.txt

dreamlife@Ubuntu:~/tutorial$ git commit -m "添加commit说明"

[issue2 ca3b9a4] 添加commit说明

1 file changed, 2 insertions(+)

dreamlife@Ubuntu:~/tutorial$ git checkout issue3

切换到分支 'issue3'

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git add myfile.txt

dreamlife@Ubuntu:~/tutorial$ git commit -m "添加pull的说明"

[issue3 6f118ad] 添加pull的说明

1 file changed, 2 insertions(+)

dreamlife@Ubuntu:~/tutorial$ git checkout master

切换到分支 'master'

dreamlife@Ubuntu:~/tutorial$ git merge issue2

更新 0151f5d..ca3b9a4

Fast-forward

myfile.txt | 2 ++

1 file changed, 2 insertions(+)

dreamlife@Ubuntu:~/tutorial$ git merge issue3

自动合并 myfile.txt

冲突(内容):合并冲突于 myfile.txt

自动合并失败,修正冲突然后提交修正的结果。

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git add myfile.txt

dreamlife@Ubuntu:~/tutorial$ git commit -m "合并issue3分支"

[master c42c43a] 合并issue3分支

dreamlife@Ubuntu:~/tutorial$ git reset --hard  HEAD`

> ^C

dreamlife@Ubuntu:~/tutorial$ git reset --hard  HEAD~

HEAD 现在位于 ca3b9a4 添加commit说明

dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git che

checkout      cherry        cherry-pick  

dreamlife@Ubuntu:~/tutorial$ git checkout issue3

切换到分支 'issue3'

dreamlife@Ubuntu:~/tutorial$ git rebase master

首先,回退分支以便在上面重放您的工作...

应用:添加pull的说明

使用索引来重建一个(三方合并的)基础目录树...

M myfile.txt

回落到基础版本上打补丁及进行三方合并...

自动合并 myfile.txt

冲突(内容):合并冲突于 myfile.txt

error: 无法合并变更。

打补丁失败于 0001 添加pull的说明

失败的补丁文件副本位于:.git/rebase-apply/patch


当您解决了此问题后,执行 "git rebase --continue"。

如果您想跳过此补丁,则执行 "git rebase --skip"。

要恢复原分支并停止变基,执行 "git rebase --abort"。


dreamlife@Ubuntu:~/tutorial$ gedit myfile.txt

dreamlife@Ubuntu:~/tutorial$ git add myfile.txt

dreamlife@Ubuntu:~/tutorial$ git rebase --continue

应用:添加pull的说明

dreamlife@Ubuntu:~/tutorial$ git checkout master

切换到分支 'master'

dreamlife@Ubuntu:~/tutorial$ git merge issue3

更新 ca3b9a4..15c5986

Fast-forward

myfile.txt | 4 ++++

1 file changed, 4 insertions(+)

dreamlife@Ubuntu:~/tutorial$

dreamlife@Ubuntu:~/tutorial$


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



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


目录
相关文章
|
2月前
|
Ubuntu Linux 网络安全
Git on Ubuntu 22.04: 终极安装与配置指南
【4月更文挑战第21天】
813 0
Git on Ubuntu 22.04: 终极安装与配置指南
|
2月前
|
Ubuntu Linux 开发工具
Linux Ubuntu配置Git的方法
Linux Ubuntu配置Git的方法
|
网络协议 Ubuntu 安全
ubuntu22.04 打开工作新局面【git加速、手机连通、git配置】
ubuntu22.04 打开工作新局面【git加速、手机连通、git配置】
1099 0
ubuntu22.04 打开工作新局面【git加速、手机连通、git配置】
|
Ubuntu 开发工具 git
UBUNTU上新建GIT库
UBUNTU上新建GIT库
69 0
|
Ubuntu Linux 网络安全
linux实用技巧:ubuntu从零开始拉取远程git空仓库并提交代码及git相关其他问题
linux实用技巧:ubuntu从零开始拉取远程git空仓库并提交代码及git相关其他问题
linux实用技巧:ubuntu从零开始拉取远程git空仓库并提交代码及git相关其他问题
|
Ubuntu Linux 网络安全
关于 ubuntu18.04使用git pull报错(没有权限) 的解决方法
关于 ubuntu18.04使用git pull报错(没有权限) 的解决方法
关于 ubuntu18.04使用git pull报错(没有权限) 的解决方法
|
Ubuntu 开发工具 git
Ubuntu安装git
Ubuntu安装git
188 0
|
安全 Ubuntu Shell
Ubuntu下使用Git_6
这回真的是最后一篇了,哈哈,改写提交。
106 0
Ubuntu下使用Git_6
|
Ubuntu 开发工具 数据库
Ubuntu下使用Git_5
还欠大家最后一篇Git的学习。
74 0
Ubuntu下使用Git_5
|
Ubuntu 数据库
Ubuntu下使用Git_3
这里是我举得小白阶段比较困难的地方了,
99 0
Ubuntu下使用Git_3