显示所有分支
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git branch
* master
|
增加分支
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git branch b1
|
切换分支
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git checkout b1
Switched to branch 'b1'
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$
|
切换到不同的分支对
helloworld.naxsu
这个文件进行修改并提交,并查看他们的内容
原先
helloworld.naxsu
的内容是
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ cat helloworld.naxsu
hello world
add something
|
在
b1
分支修改并提交,然后查看文件内容
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ vim helloworld.naxsu
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ git commit -a -m "b1 update
helloworld.naxsu"
warning: LF will be replaced by CRLF in
helloworld.naxsu.
The file will have its original line
endings in your working
[b1 warning: LF will be replaced by CRLF
in helloworld.naxsu
The file will have its original line
endings in your working
b9c5de1] b1 update helloworld.naxsu
warning: LF will be replaced by CRLF in
helloworld.naxsu.
The file will have its original line
endings in your working
1
file changed, 1 insertion(+)
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ git status
# On branch b1
nothing to commit (working directory
clean)
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ cat helloworld.naxsu
hello world
add something
b1 branch add something
|
切换到
master
分支,进行和上面一样的操作
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master'
by 7 commits.
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ vim helloworld.naxsu
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git commit -a -m "master update
helloworld.naxsu"
[master d9f15c9] master update helloworld.naxsu
1
file changed, 1 insertion(+)
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ cat helloworld.naxsu
hello world
add something
master branch add something
|
从中可以看出两个分支是没有影响的。
##########NextPage##########
列出各分支之间的信息
huangyineng@HUANGYINENG-PC ~/hello-world (master)
$ git show-branch
! [b1] b1 update helloworld.naxsu
*
[master] master update helloworld.naxsu
--
*
[master] master update helloworld.naxsu
+
[b1] b1 update helloworld.naxsu
+* [master^] delete test.naxsu
|
比较
master
和
b1
这两个分支文件的不同
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git diff master b1
diff --git a/helloworld.naxsu
b/helloworld.naxsu
index 9e73a56..7929722 100644
--- a/helloworld.naxsu
+++ b/helloworld.naxsu
@@ -1,3 +1,3 @@
hello world
add something
-master branch add something
+b1 branch add something
|
分支合并
merge
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git merge "merge" HEAD b1
Auto-merging helloworld.naxsu
CONFLICT (content): Merge conflict in
helloworld.naxsu
Automatic merge failed; fix conflicts and
then commit the result.
|
显示自动合并失败,我们看一下状态,可以看到
helloworld.naxsu
被两个分支修改过了
huangyineng@HUANGYINENG-PC ~/hello-world
(master|MERGING)
$ git status
# On branch master
# Your branch is ahead of 'origin/master'
by 8 commits.
#
# Unmerged paths:
#
(use "git add/rm ..." as appropriate to mark
resolution)
#
#
both modified:
helloworld.naxsu
#
no changes added to commit (use "git
add" and/or "git commit -a")
|
我们来看一下
helloworld.naxsu
的内容
huangyineng@HUANGYINENG-PC ~/hello-world
(master|MERGING)
$ cat helloworld.naxsu
hello world
add something
<<<<<<< HEAD
master branch add something
=======
b1 branch add something
>>>>>>> b1
|
把们用
vim
编辑工具人为的把冲突去掉,然后保存、提交,切换到其他分支,也可以看到没有冲突了
huangyineng@HUANGYINENG-PC ~/hello-world
(master|MERGING)
$ vim helloworld.naxsu
huangyineng@HUANGYINENG-PC ~/hello-world
(master|MERGING)
$ git commit -a -m "merging"
[master 34908f4] merging
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ cat helloworld.naxsu
hello world
add something
master branch add something
b1 branch add something
huangyineng@HUANGYINENG-PC ~/hello-world
(master)
$ git checkout b1
Switched to branch 'b1'
huangyineng@HUANGYINENG-PC ~/hello-world
(b1)
$ cat helloworld.naxsu
hello world
add something
b1 branch add something
|
另一种合并的做法,自行去查帮助文档:
$ git checkout master
$ git pull . b1
本文链接:
http://www.656463.com/portal.php?mod=view&aid=7
2
,转载请注明出处
下一节:
标签
分享到:
相关推荐
借助于Git强大的分支、合并、日志、历史追溯、rebase、submodule、subtree等一系列特性,开发者之间的协作变得越来越容易。 Git是由Linus Torvalds开发的;同时,Linus Torvalds也是Linux之父。他开发的这两款软件...
本文档讲述了Git的概述、工作流程、软件安装、常用命令、分支操作、远程操作、IDEA使用Git、GitLab自建代码托管平台等内容,通俗易懂,简明扼要,零基础入门Git实战。声明:本文档所涉及到的图片均引用官方文档或...
18.4.4 将 user1/getopt 分支合并到主线/ 264 18.5 基于发布分支的开发/ 265 18.5.1 创建发布分支/ 266 18.5.2 开发者 user1 工作在发布分支/ 267 18.5.3 开发者 user2 工作在发布分支/ 268 18.5.4 开发者 user2 ...
本系列课程从git基础到项目实战,老师手把手教你如何使用git来管理项目,进行代码的推送、拉取、提交以及分支相关操作,课程体系完整清晰。 1.Git入门 1.1简介 1.2Git 与 SVN 区别 1.3 Git的安装 1.4git本地仓库...
29.Git分支管理的本质是创建和移动指针 30.GitHub账号注册 31.修改GitHub账号头像 32.本地库和远程库交互方式回顾 33.为了测试远程交互初始化新的本地库 34.创建远程库 35.在本地创建远程库地址别名 36.推送操作 37....
第4篇全面介绍了git的协同模型,即它在实际工作中的使用模式,包括各种经典的git协同模型、topgit协同模型、子模组协同模型、子树合并、android多版本库协同、git与svn协同模型等。第5篇介绍了git服务器的架设,首先...
本套课程将会讲解git的使用基础,主要包括:git的安装与配置、深刻理解工作区、暂存区的区别,git分支合并的原理、深入理解git对象的组成,总结来讲就是将基础知识的同时也同时讲解实现原理,带领大家更加深刻地理解...
第4篇全面介绍了git的协同模型,即它在实际工作中的使用模式,包括各种经典的git协同模型、topgit协同模型、子模组协同模型、子树合并、android多版本库协同、git与svn协同模型等。第5篇介绍了git服务器的架设,首先...
02 文件合并与文件归档 03 文件归档与两种压缩方式 04 vim编辑器 05 系统启动流程 06 grub加密 07 bios加密 08 top命令 09 free命令 10 进程管理 第6章 01 上节课复习 02 磁盘分区 03 文件系统与挂载 04 挂载信息...
这是项目的一个分支,合并了所有挂起的拉取请求。 s3_website能为您做什么 为您创建和配置 S3 网站 将您的静态网站上传到 AWS S3 , , 和 自动支持 帮助您使用 AWS Cloudfront 分发您的网站 通过 HTTP 缓存控制和 ...