Git分支

​ 分支即是平行空间,假设你在为某个手机系统研发拍照功能,代码已经完成了80%,但如果将这不完整的代码直接提交到git仓库中,又有可能影响到其他人的工作,此时我们便可以在该软件的项目之上创建一个名叫"拍照功能"的分支,这种分支只会属于你自己,而其他人看不到,等代码编写完成后再与原来的项目主分支合并下即可,这样即能保证代码不丢失,又不影响其他人的工作。

一般在实际的项目开发中,我们要尽量保证master分支是非常稳定的,仅用于发布新版本,平时不要随便直接修改里面的数据文件,而工作的时候则可以创建不同的工作分支,等到工作完成后在合并到master分支上面,所以团队的合作分支看起来会像上面的图那样。
[root@git ~/git_data]# git log --oneline --decorate
ef16b0b (HEAD, master) add ddd #默认分支指向你最后一次的提交 HEAD头、指针
6118c8d add bbb #HEAD 指针指向哪个分支、说明你当前在哪个分支下工作18c89e4 modified a
1a85735 rename a.txt
a64e0f41 commit a.txt
c6b0ac2 new file a

1.新建testing分支

[root@git ~/git_data]# git branch testing
# *号在哪里就说明当前在哪个分支上如下图所示:
[root@git ~/git_data]# git branch
* master
testing

#通过命令查看分支指向
[root@git ~/git_data]# git log --oneline --decorate
ef16b0b (HEAD, testing, master) add ddd
6118c8d add bbb
18c89e4 modified a
1a85735 rename a.txt
a64e0f41 commit a.txt
c6b0ac2 new file a
#切换到testing分支、对应的HEAD指针也指向了testing
[root@git ~/git_data]# git checkout testing
Switched to branch 'testing'
#HEAD指针指向了testing
[root@git ~/git_data]# git branch
master
* testing

[root@git ~/git_data]# touch test
[root@git ~/git_data]# git add .
[root@git ~/git_data]# git commit -m 'commit test'
[testing 0924a70] commit test
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test
[root@git ~/git_data]# git log --oneline --decorate
0924a70 (HEAD, testing) commit test
ef16b0b (master) add ddd
6118c8d add bbb
18c89e4 modified a
1a85735 rename a.txt a
64e0f41 commit a.txt
c6b0ac2 new file a

[root@git ~/git_data]# git checkout master
Switched to branch 'master'
[root@git ~/git_data]# git branch
* master
testing
[root@git ~/git_data]# ll #正常情况下是没有test文件的、保证master分支是线上环境的total 4
-rw-r--r-- 1 root root 16 Oct 20 18:36 a

[root@git ~/git_data]# touch master
[root@git ~/git_data]# git add .
[root@git ~/git_data]# git commit -m "commit master"
[master 8efaada] commit master
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 master
[root@git ~/git_data]# ll
total 4
-rw-r--r-- 1 root root 16 Oct 20 18:36 a-rw-r--r-- 1 root root 0 Nov 16 12:21 master

2.合并分支

[root@git ~/git_data]# git merge testing
Merge branch 'testing'
#Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
merge testing to master #提示输入描述信息,相当于git的-m参数
#查看日志记录
[root@git ~/git_data]# git log --oneline --decorate
0fcf3ce (HEAD, master) Merge branch 'testing'
8efaada commit master
0924a70 (testing) commit teste
f16b0b add ddd
6118c8d add bbb
18c89e4 modified a
1a85735 rename a.txt
a64e0f41 commit a.txt
c6b0ac2 new file a

3.合并冲突

[root@git ~/git_data]# echo "master" >> a
[root@git ~/git_data]# git commit -am "modified a master"
[master a3d84f3] modified a master
1 file changed, 1 insertion(+)
[root@git ~/git_data]# git checkout testing
Switched to branch 'testing'
[root@git ~/git_data]# git branch
master
* testing
[root@git ~/git_data]# cat a
aaa
ccc
bbb
ddd
[root@git ~/git_data]# echo "testing" >>a
[root@git ~/git_data]# git commit -am "modified a on testing branch"
[testing 23dec52] modified a on testing branch
1 file changed, 1 insertion(+)
[root@git ~/git_data]# git checkout master
Switched to branch 'master'
[root@git ~/git_data]# git merge testing
Auto-merging a
CONFLICT (content): Merge conflict in a
Automatic merge failed; fix conflicts and then commit the result.
[root@git ~/git_data]# cat a #冲突的文件自动标识到文件里,手动更改冲突要保留的代码
aaa
ccc
bbb
ddd
<<<<<<< HEAD
master
=======
testing
>>>>>>> testing
[root@git ~/git_data]# git commit -am "merge testing to master" #提交
[master 5beb7bb] merge testing to master
[root@git ~/git_data]# git log --oneline --decorate
5beb7bb (HEAD, master) merge testing to master
23dec52 (testing) modified a on testing branch
a3d84f3 modified a master
0fcf3ce Merge branch 'testing'
8efaada commit master
0924a70 commit test
ef16b0b add ddd
6118c8d add bbb
18c89e4 modified a
1a85735 rename a.txt
a64e0f41 commit a.txt
c6b0ac2 new file a

4.删除分支

[root@git ~/git_data]# git branch -d testing
Deleted branch testing (was 23dec52).
[root@git ~/git_data]# git branch
* master

Git标签使用

标签也是指向了一次commit提交,是一个里程碑式的标签,回滚打标签直接加标签号,不加唯一字符串不好记

#-a指定标签名字 -m 指定说明文字
[root@git ~/git_data]# git tag -a v1.0 -m "aaa bbb master tesing version v1.0"

1.查看标签

[root@git ~/git_data]# git tag
v1.0
# 指定某一次的提交为标签
[root@git ~/git_data]# git tag -a v2.0 0924a70 -m "add bbb version v2.0"
# 查看v1.0的信息 git show 加标签查看
[root@git ~/git_data]# git reset --hard v2.0
HEAD is now at 0924a70 commit test
[root@git ~/git_data]# ll
total 4
-rw-r--r-- 1 root root 16 Nov 16 15:04 a
-rw-r--r-- 1 root root 0 Nov 16 12:22 test

02.删除标签

[root@git ~/git_data]# git tag -d v2.0
Deleted tag 'v2.0' (was b0b964c)
[root@git ~/git_data]# git tagv1.0

Git--03 git分支的更多相关文章

  1. Git - 03. git 工作空间

    1. 概述 git 存放代码的地方 2. 创建 命令 # 1. 从无到有 > git init # 2. 从远程拉去现有的仓库 > git clone <url> 3. 文件生 ...

  2. git合并远端分支到本地分支的两种方式

    作者:zhanhailiang 日期:2014-11-21 在使用版本号工具提交改动之前,都须要通过update先将本地代码更新到最新版本号.SVN通过svn update就能够实现,那么git怎样实 ...

  3. Git Pro - (2)分支

    Git 保存的不是文件差异或者变化量,而只是一系列文件快照. 在 Git中提交时,会保存一个提交(commit)对象,它包含一个指向暂存内容快照的指针,作者和相关附属信息,以及一定数量(也可能没有)指 ...

  4. Git远程和分支管理

    一.远程       Git是分布式版本控制系统,最重要的优点就是远程仓库托管代码.不用自己搭建一个服务器,在github上面注册一个账户就可免费获取远程仓库.      首先需要先在github上面 ...

  5. git 基于发布分支的开发

    创建发布分支: (1) 软件hello-world的1.0发布版本库中有一个里程相对应. /home/jackluo/workspace/user1/workspace/hello-worldgit ...

  6. git 创建branch分支

    开发者user1 负责用getopt 进行命令解析的功能,因为这个功能用到getopt 函数,于是将这个分支命名为user1/getopt.(1)确保是在开发者user1的工作区中cd /home/j ...

  7. git基础及分支

    关于版本控制 git是一种分布版本控制系统,每一主机都保存了完整副本.必杀技是分支. 在Windows可安装git客户端msysgit. git基础 第一次看progit觉得有点不懂,不懂版本控制,一 ...

  8. git 创建branch分支【转】

    转自:http://www.cnblogs.com/jackluo/p/3499731.html 开发者user1 负责用getopt 进行命令解析的功能,因为这个功能用到getopt 函数,于是将这 ...

  9. Git教程之分支管理之二

    分支管理策略 通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息.如果要强制禁用Fast forward模式,Git就会在merge时生成一个 ...

  10. Git教程之分支管理之一

    分支在实际中有什么用呢? 你创建了一个属于你自己的分支,别人看不到,别人还继续在原来的分支上正常工作,而你在自己的分支上干活,想提交就提交,直到开发完毕后,再一次性合并到原来的分支上,这样,既安全,又 ...

随机推荐

  1. 06.队列、python标准库中的双端队列、迷宫问题

    class QueueUnderflow(ValueError): """队列为空""" pass class SQueue: def __ ...

  2. Django的下载和基本指令

    1.下载Django pip3  install  django     #不写版本号的话,默认使下载最新版的django pip3  install   django == 2.1.2    #指定 ...

  3. 数组与List互转的坑

    一.数组转List 非原始类型的数组转List有很多种方式:假设有Integer[] arr = {"a", "b", "c"}; 1.Li ...

  4. 【Java】Java URLDecoder异常Illegal hex characters in escape (%)

    如果收到的HTTP请求参数(URL中的GET请求)中有一个字符串,是中文,比如“10%是黄段子”,服务器段使用URLDecoder.decode就会出现此异常.URL只能使用英文字母.阿拉伯数字和某些 ...

  5. String reduction (poj 3401

    String reduction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1360   Accepted: 447 D ...

  6. Flueme学习之路(一)Flume的基础介绍

    背景 Hadoop业务的整体开发流程: ​ 从Hadoop的业务开发流程中可以看出,在大数据的业务处理流程中,对于数据的采集是十分重要的一步,也是不可避免的一步. ​ 许多公司的平台每天会产生大量的日 ...

  7. List of yellow pages

    List of yellow pages From Wikipedia, the free encyclopedia   [hide]This article has multiple issues. ...

  8. day07——css布局解决方案之居中布局

     转行学开发,代码100天——2018-03-23 1.水平居中 使用inline-block + text-align方法 先将子框由块级元素改为行内块元素,再通过设置行内块元素居中以实现水平居中 ...

  9. DR 项目小结

    前言 个人的项目总结, 非技术类博文. 需要补充的知识点 HTTP 协议与其内置方法 curl 指令和各选项的意义 Keystone 认证流程和各项目配置文件 [keystone_authtoken] ...

  10. java 虚方法。 后面new 那个类, 就调用哪个类的方法 ,而非定义类的方案。 关于父子 类的 呵呵

    java   虚方法.     后面new  那个类, 就调用哪个类的方法 ,而非定义类的方案.  关于父子 类的   呵呵 在多态的情况下,声明为父类类型的引用变量只能调用父类中的方法,但如果此变量 ...