├── .DS_Store ├── Git中HEAD 是什么东西,为什么会出现在分支里.md ├── LICENSE ├── README.md ├── git commit 规范.md ├── github如何精准分享关键代码.md ├── gitlab和github一起使用.md ├── git参考资料.md ├── git工作流gitflow的分支简介.md ├── git常用命令速查表.md ├── images ├── .DS_Store ├── 15_48_34__05_02_2018.jpg ├── 15_49_16__05_02_2018.jpg ├── 15_49_42__05_02_2018.jpg ├── 20141230143856975.png ├── 20141230143916421.png ├── 20141230143942948.png ├── 20141230144015116.png ├── 20141230144036207.png ├── 2147642-42195cacced56729.png ├── 5819ab860001e6b120481446.jpg ├── 58a025c200016a8712800720.jpg ├── 58e8eb560001ecfd12800720.jpg ├── gitconfig.jpeg ├── rebase-1.png ├── rebase-2.png ├── rebase-3.png └── v2-6351aba6f4b722630d0b3086dcab2927_hd.jpg ├── 使用git rebase合并多次commit.md ├── 利用tag管理项目版本号.md └── 如何安装git.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/.DS_Store -------------------------------------------------------------------------------- /Git中HEAD 是什么东西,为什么会出现在分支里.md: -------------------------------------------------------------------------------- 1 | 2 | ## 理解git中的HEAD、head和master 3 | 4 | 5 | ### 1. 概念 6 | 7 | 说简单一点,HEAD就是当前活跃分支的游标。 8 | 9 | 形象的记忆就是:你现在在哪儿,HEAD就指向哪儿,所以Git才知道你在那儿! 10 | 11 | 不过HEAD并非只能指向分支的最顶端(时间节点距今最近的那个),实际上它可以指向任何一个节点,它就是 Git内部用来追踪当前位置的东东。 12 | 13 | 14 | ### 2. HEAD和head 15 | 16 | 你可以认为 HEAD(大写)是"current branch"(当下的分支)。当你用git checkout切换分支的时候,HEAD 修订版本重新指向新的分支。有的时候HEAD会指向一个没有分支名字的修订版本,这种情况叫”detached HEAD“ 17 | 18 | head(小写)是commit对象的引用,每个head都有一个名字(分支名字或者标签名字等等),但是默认情况下,每个叫master的repository都会有一个head, 一个repository可以包含任意数量的head。在任何时候,只要这个head被选择成为”current head“,那么这个head就成了HEAD,总是大写 19 | 20 | 21 | ### 3. 图解HEAD 22 | 23 | 在master分支上,HEAD指向master,而master指向的是最近的一次提交。如下图 24 | 25 | ![1](https://github.com/zuopf769/how_to_use_git/blob/master/images/20141230143856975.png) 26 | 27 | 当我们新建分支时,比如新建分支Dev,Dev会指向当前master分支的最近一次提交。 28 | 29 | 当我们使用命令: 30 | 31 | ``` 32 | git checkout dev 33 | 34 | ``` 35 | 切换到Dev分支后,HEAD就指向当前分支Dev了。 36 | 37 | ![2](https://github.com/zuopf769/how_to_use_git/blob/master/images/20141230143916421.png) 38 | 39 | 40 | 在Dev上修改,比如修改helloworld.c,然后提交,分支Dev指向当前分支的最新提交,而master指向master分支的最新提交。 41 | 42 | 切换回到master分支: 43 | 44 | ``` 45 | git checkout master 46 | 47 | ``` 48 | 49 | 然后再master分支上查看helloworld.c,我们发现并没有被修改。 50 | 51 | ![3](https://github.com/zuopf769/how_to_use_git/blob/master/images/20141230143942948.png) 52 | 53 | 为了将在分支Dev上所做的修改也作用的master分支上,也就是说将Dev分支合并(merge)到master分支上。 54 | 55 | ``` 56 | git merge dev 57 | 58 | ``` 59 | 这时候master指向了Dev的最近一次提交。而head指向当前分支即master。 60 | 61 | ![4](https://github.com/zuopf769/how_to_use_git/blob/master/images/20141230144015116.png) 62 | 63 | 当利用分支Dev做好修改工作后,就可以把Dev删除掉。兔死狗烹,卸磨杀驴。 64 | 65 | ``` 66 | git branch -d dev 67 | 68 | ``` 69 | ![5](https://github.com/zuopf769/how_to_use_git/blob/master/images/20141230144036207.png) 70 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 zuopengfei01 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GIT系列 2 | -------------------------------------------------------------------------------- /git commit 规范.md: -------------------------------------------------------------------------------- 1 | # git commit 规范 2 | 3 | + feat: 新功能 4 | + fix: 修复问题 5 | + docs: 修改文档 6 | + style: 修改代码格式,不影响代码逻辑 7 | + refactor: 重构代码,理论上不影响现有功能 8 | + perf: 提升性能 9 | + test: 增加修改测试用例 10 | + chore: 修改工具相关(包括但不限于文档、代码生成等) 11 | + deps: 升级依赖 12 | 13 | 例如, 14 | ``` 15 | git commit -m 'fix:修复xxxbug' 16 | ``` 17 | -------------------------------------------------------------------------------- /github如何精准分享关键代码.md: -------------------------------------------------------------------------------- 1 | ## github如何精准分享关键代码 2 | 3 | > [左鹏飞](https://github.com/zuopf769) 2017.09.31 4 | 5 | ### #L行号 6 | 7 | 比如你有一个文件里的某一行代码写得非常酷炫或者关键,想分享一下。可以在url后面加上 `#L行号`。 8 | 9 | 比如,点击下面这个url: 10 | 11 | [https://github.com/AlloyTeam/AlloyTouch/blob/master/alloy_touch.js#L240](https://github.com/AlloyTeam/AlloyTouch/blob/master/alloy_touch.js#L240) 12 | 13 | 你便会跳到alloy_touch.js的第240行。 14 | 15 | 16 | ### #L开始行号-L结束行号 17 | 18 | 那么问题来了?如果我是一段代码,即多行代码想分享呢?也很简单:url后面加上`#L开始行号-L结束行号`. 19 | 20 | 21 | 比如,AlloyTouch的运动缓动和逆向缓动函数如下面代码段所示: 22 | https://github.com/AlloyTeam/AlloyTouch/blob/master/alloy_touch.js#L39-L45 23 | 24 | 其实也不用自己在网址后面操作,github自动会帮你生成url。 25 | 26 | + 比如你点击39行,url变成了 27 | https://github.com/AlloyTeam/AlloyTouch/blob/master/alloy_touch.js#L39 28 | 29 | 30 | + 再按住shift点击45行,url变成了 31 | https://github.com/AlloyTeam/AlloyTouch/blob/master/alloy_touch.js#L39-L45 32 | 33 | 34 | 然后你这个url就可以复制分享出去了,点击这个url的人自动会跳到39行,并且39-45行高亮。 35 | 36 | -------------------------------------------------------------------------------- /gitlab和github一起使用.md: -------------------------------------------------------------------------------- 1 | ## gitlab和github一起使用 2 | 3 | > [左鹏飞](https://github.com/zuopf769) 2017.09.28 4 | 5 | ### 1. 背景 6 | 7 | 通常公司用gitlab来做代码的版本管理和协同开发;而我们有个人的github账号。那咋样才能在一台电脑上同时使用gitlab和github呢? 8 | 9 | ### 2. 操作步骤 10 | 11 | #### 2.1 首先都已经注册了gitlab和github的账户 12 | 13 | #### 2.2 生成公钥、秘钥 14 | 15 | ssh-keygen -t rsa -C "注册的gitlab邮箱" 16 | 17 | 名称输入gitlab_id_rsa 18 | 19 | ssh-keygen -t rsa -C "注册的github邮箱" 20 | 21 | 名称输入github_id_rsa 22 | 23 | 除了名称外,其他一路回车。 24 | 25 | 完成后会在~/.ssh/目录下生成以下文件: 26 | 27 | + github_id_rsa 28 | + github_id_rsa.pub 29 | + gitlab_id_rsa 30 | + gitlab_id_rsa.pub 31 | 32 | 33 | #### 2.3 将两个pub文件分别配置到github和gitlab的sshkey中 34 | 35 | 36 | #### 2.4 编写config文件,告诉本地git到不同的托管平台带不同的钥匙。 37 | 38 | ``` 39 | cd ~/.ssh 40 | vi config 41 | ``` 42 | 43 | 44 | config内容如下: 45 | 46 | ``` 47 | 48 | #gitlab 49 | Host gitlab 50 | HostName gitlab.*.com 51 | IdentityFile ~/.ssh/gitlab_id_rsa 52 | 53 | #github 54 | Host github 55 | HostName github.com 56 | IdentityFile ~/.ssh/github_id_rsa 57 | 58 | ``` 59 | 60 | + Host可以使用通配符,当ssh的时候如果server的URL能match上这里Host指定的值,则Host下面指定的HostName将被作为最终URL使用。同时该Host下配置的User, Port都将被使用。 61 | 62 | + ssh的server的URL如下图所示 63 | 64 | ![](https://github.com/zuopf769/how_to_use_git/blob/master/images/gitconfig.jpeg) 65 | 66 | + HostName根据自己实际需求来定 67 | 68 | 69 | #### 2.5 配置仓库 70 | 71 | ``` 72 | github工作仓库:~/workspace/github 73 | gitlab工作仓库:~/workspace/gitlab 74 | 75 | ``` 76 | 77 | ``` 78 | #gitlab 79 | cd ~/workspace/gitlab 80 | git init 81 | git config --global user.name 'personal' 82 | git config --global user.email 'personal@company.com' 83 | 84 | ``` 85 | 86 | ``` 87 | #github 88 | cd ~/workspace/github 89 | git init 90 | git config --local user.name 'kingboy' 91 | git config --local user.email 'kingboy@163.com' 92 | 93 | ``` 94 | 95 | > 注意 96 | > 97 | > + 把工作用的gitlab的git config配置设置成全局的 98 | > + github的git config配置设置成本地 99 | 100 | 101 | #### 2.6 接下来在两个目录下新建或者clone项目开发即可. 102 | 103 | 104 | #### 2.7 解决只能http协议clone成功,ssh协议不能成功的问题 105 | 106 | 107 | 添加公钥到github和gitlab的个人账户后,分别执行 ssh -v git@github.com ssh -v git@gitlab.*.com测试能否正常ssh链接;在日志里面可以查看到并未使用我们新生成的private私钥;而是使用默认的id_rsa,所以会报Permission denied (publickey). 108 | 109 | 执行ssh-add -l命令显示密钥列表为空,所以要添加我们新生成的密钥;ssh-add ~/.ssh/github_id_rsa ssh-add ~/.ssh/gitlab_id_rsa.pub; 使用ssh-add -l查看是否成功 110 | 111 | 最后执行git clone ssh://xxxx就可以成功了 112 | 113 | 114 | ### 3 参考资料 115 | 116 | + [ssh config配置](http://www.xuebuyuan.com/414672.html) 117 | 118 | -------------------------------------------------------------------------------- /git参考资料.md: -------------------------------------------------------------------------------- 1 | GIT参考资料 2 | 3 | 4 | 1. [git参考手册](http://gitref.justjavac.com/index.html) 5 | 6 | 2. [Pro Git(中文版)](http://git.oschina.net/progit/) 7 | 8 | 3. [Git教程](https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00137402760310626208b4f695940a49e5348b689d095fc000) 9 | -------------------------------------------------------------------------------- /git工作流gitflow的分支简介.md: -------------------------------------------------------------------------------- 1 | # 简单介绍git工作流gitflow的分支 2 | 3 | > 左鹏飞 2017.8.27 4 | 5 | ## 一、gitflow 6 | + 1、gitflow定义了一个围绕项目发布的严格的分支模型 7 | + 2、gitflow仍然用中央仓库作为所有开发者的交互中心。 8 | 9 | gitflow示意图 10 | 11 | ![gitflow示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/58e8eb560001ecfd12800720.jpg) 12 | 13 | ## 二、gitflow包括哪些分支 14 | 15 | + master: maseter主分支,存储正式发布的历史。发布的时候会打个tag,也就是版本号 16 | + hotfix: 上线分支,bug情急修复分支 17 | + release:发布分支,发布上线的时候用 18 | + develop:开发分支,作为功能的收集分支 19 | + feature:功能分支,每次开发新功能的时候都会有对应的feature分支,同时会有几个不同的feature分支 20 | 21 | ## 三、各个分支之间的交互 22 | + develop分支是从master主干checkout出来的 23 | + feature分支是从develop分支checkout出来的,feature分支功能开发完成后会merge回develop分支 24 | + 同时可能会有多个feature分支,处理不同的功能 25 | + develop分支开发到一个里程碑的时候,就需要合入到release分支,用于QA测试回归,如果没有问题,就merge回master主干,然后在主干上release一个版本 26 | + 当线上出现紧急bug时,可以从master主干checkout一个hotfix分支,修复完bug后,merge会主干,紧急release一个新的版本;然后hotfix分支需要合并到develop分支,因为develop分支需要和master分支保持同步 27 | + hotfix分支、release分支、feature分支完成使命后就可以删掉了,而master,和develop分支始终都存在 28 | 29 | ## 四、历史分支和功能分支的区别 30 | 31 | 32 | ![历史分支和功能分支的区别](https://github.com/zuopf769/how_to_use_git/blob/master/images/58a025c200016a8712800720.jpg) 33 | 34 | ### 历史分支 35 | > 相对使用仅有的一个master分支,Gitflow工作流使用2个分支来记录项目的历史。master分支存储了正式发布的历史,而develop分支作为功能的集成分支。这样也方便master分支上的所有提交分配一个版本号。 36 | 37 | ### 功能分支 38 | 39 | #### 基本概念 40 | 41 | > 每个新功能位于一个自己的分支,这样可以push到中央仓库以备份和协作。但功能分支不是从master分支上拉出新分支,而是使用develop分支作为父分支。当新功能完成时,合并回develop分支。新功能提交应该从不直接与master分支交互。 42 | feature分支是从develop打出来的。 43 | 44 | #### 使用原则 45 | 46 | + 新功能提交应该从不直接与master分支交互。 47 | + 分支名称feature/[feature name]。 48 | 49 | ### 工作流程 50 | 51 | + 使用develop分支作为父分支, 52 | + 每个新功能位于一个自己的分支 53 | + 新功能完成后,合并回develop分支。 54 | 55 | #### 使用规范 56 | + 可以从develop分支发起feature分支 57 | + 代码必须合并回develop分支 58 | + feature分支的命名可以使用除master,develop,release-*,hotfix-*之外的任何名称 59 | + feature分支(有时也可以被叫做“topic分支”)通常是在开发一项新的软件功能的时候使用,这个分支上的代码变更最终合并回develop分支或者干脆被抛弃掉(例如实验性且效果不好的代码变更)。 60 | + 一般而言,feature分支代码可以保存在开发者自己的代码库中而不强制提交到主代码库里。 61 | 62 | 63 | ## 五、发布分支 64 | 65 | ### 基本概念 66 | 67 | release分支是为发布新的产品版本而设计的。在这个分支上的代码允许做小的缺陷修正、准备发布版本所需的各项说明信息(版本号、发布时间、编译时间等等)。通过在release分支上进行这些工作可以让develop分支空闲出来以接受新的feature分支上的代码提交,进入新的软件开发迭代周期。 68 | 69 | ### 啥时候需要release分支 70 | 71 | 当develop分支上的代码已经包含了所有即将发布的版本中所计划包含的软件功能,并且已通过所有测试时,我们就可以考虑准备创建release分支了。而所有在当前即将发布的版本之外的业务需求一定要确保不能混到release分支之内(避免由此引入一些不可控的系统缺陷)。 72 | 73 | ### 使用规范: 74 | + 可以从develop分支派生、使用develop分支作为父分支。 75 | + 这个分支只应该做bug修复、文档生成和其它面向发布的任务。 76 | + 发布完成之后,发布分支应该合并到master分支并分配一个版本号打好tag。 77 | + 从新建发布分支以来的做的修改要合并回develop分支。 78 | + 分支命名惯例:release-* 79 | + 当前发布分支名称:release/[release version No.] 80 | + 当前发布bug修复分支名称:release-bugfix-[Version No.]/[bug name|bug No.] 81 | 82 | ### release之后 83 | 84 | 成功的派生了release分支,并被赋予版本号之后,develop分支就可以为“下一个版本”服务了。所谓的“下一个版本”是在当前即将发布的版本之后发布的版本。版本号的命名可以依据项目定义的版本号命名规则进行。 85 | 86 | 87 | -------------------------------------------------------------------------------- /git常用命令速查表.md: -------------------------------------------------------------------------------- 1 | git常用命令速查表 2 | 3 | ![git常用命令速查表](https://github.com/zuopf769/how_to_use_git/blob/master/images/5819ab860001e6b120481446.jpg) 4 | -------------------------------------------------------------------------------- /images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/.DS_Store -------------------------------------------------------------------------------- /images/15_48_34__05_02_2018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/15_48_34__05_02_2018.jpg -------------------------------------------------------------------------------- /images/15_49_16__05_02_2018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/15_49_16__05_02_2018.jpg -------------------------------------------------------------------------------- /images/15_49_42__05_02_2018.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/15_49_42__05_02_2018.jpg -------------------------------------------------------------------------------- /images/20141230143856975.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/20141230143856975.png -------------------------------------------------------------------------------- /images/20141230143916421.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/20141230143916421.png -------------------------------------------------------------------------------- /images/20141230143942948.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/20141230143942948.png -------------------------------------------------------------------------------- /images/20141230144015116.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/20141230144015116.png -------------------------------------------------------------------------------- /images/20141230144036207.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/20141230144036207.png -------------------------------------------------------------------------------- /images/2147642-42195cacced56729.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/2147642-42195cacced56729.png -------------------------------------------------------------------------------- /images/5819ab860001e6b120481446.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/5819ab860001e6b120481446.jpg -------------------------------------------------------------------------------- /images/58a025c200016a8712800720.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/58a025c200016a8712800720.jpg -------------------------------------------------------------------------------- /images/58e8eb560001ecfd12800720.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/58e8eb560001ecfd12800720.jpg -------------------------------------------------------------------------------- /images/gitconfig.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/gitconfig.jpeg -------------------------------------------------------------------------------- /images/rebase-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/rebase-1.png -------------------------------------------------------------------------------- /images/rebase-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/rebase-2.png -------------------------------------------------------------------------------- /images/rebase-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/rebase-3.png -------------------------------------------------------------------------------- /images/v2-6351aba6f4b722630d0b3086dcab2927_hd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zuopf769/how_to_use_git/3d59a5f12e71a9dab52158ff3461a912369bfe55/images/v2-6351aba6f4b722630d0b3086dcab2927_hd.jpg -------------------------------------------------------------------------------- /使用git rebase合并多次commit.md: -------------------------------------------------------------------------------- 1 | ## 使用git rebase合并多次commit 2 | 3 | [左鹏飞](https://github.com/zuopf769) 2018.5.2 4 | 5 | ### 1. 背景 6 | 7 | 一个repo通常是由一个team中的多个人共同维护,如果需要增加新feature,那么就是一个feature分支了。由于开发中各种修改,本feature分支多次commit。最后提交master后,会看到乱七八糟的所有增量修改历史。其实对别人来说,我们的改动应该就是增加或者删除,给别人看开发过程的增量反而太乱。于是我们可以将feature分支的提交合并后然后再merge到主干这样看起来就清爽多了。 8 | 9 | 10 | 记得知乎上有个帖子提问为啥vue的作者尤大大在开发vue的时候,提交历史能做到如此清爽。[Git commits历史是如何做到如此清爽的? - 知乎](https://www.zhihu.com/question/61283395) 11 | 12 | ![vue commit log](https://github.com/zuopf769/how_to_use_git/blob/master/images/v2-6351aba6f4b722630d0b3086dcab2927_hd.jpg) 13 | 14 | 15 | ### 2. rebase简介 16 | 17 | rebase的作用简要概括为:可以对某一段线性提交历史进行编辑、删除、复制、粘贴;因此,合理使用rebase命令可以使我们的提交历史干净、简洁! 18 | 19 | 但是需要注意的是: 20 | > 不要通过rebase对任何已经提交到公共仓库中的commit进行修改(你自己一个人玩的分支除外) 21 | 22 | 23 | ### 3. 反面例子 24 | 25 | 新建一个repo `rebase-test`;新建开发分支`dev`;在开发分支是`commit`了三次然后`merge`到`master`分支;然后`git log `或者`git log --oneline`;可以发现`dev`分支上的每次`commit `都体现到了`master`上 26 | 27 | ``` 28 | fb28c8d (HEAD -> master, origin/master, origin/dev, origin/HEAD, dev) fix: 第三次提交 29 | 47971f6 fix: 第二次提交 30 | d2cf1f9 fix: 第一次提交 31 | 26bac61 Initial commit 32 | 33 | ``` 34 | 35 | > 如果用`git log `可以按`s`向下翻`log` 36 | > 37 | > `git log --oneline` 可以一行展现 38 | 39 | 40 | ### 4. 具体操作 41 | 42 | 当我们在本地仓库中提交了多次,在我们把本地提交push到公共仓库中之前,为了让提交记录更简洁明了,我们希望把如下分支B、C、D三个提交记录合并为一个完整的提交,然后再push到公共仓库。 43 | 44 | ![rebase示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/2147642-42195cacced56729.png) 45 | 46 | 这里我们使用命令: 47 | 48 | ```javascript 49 | git rebase -i [startpoint] [endpoint] 50 | 51 | ``` 52 | 53 | 其中`-i`的意思是`--interactive`,即弹出交互式的界面让用户编辑完成合并操作,`[startpoint] [endpoint]`则指定了一个编辑区间,如果不指定`[endpoint]`,则该区间的终点默认是当前分支HEAD所指向的commit(注:该区间指定的是一个前开后闭的区间)。 54 | 在查看到了log日志后,我们运行以下命令: 55 | 56 | ``` 57 | git rebase -i 36224db 58 | ``` 59 | 或者 60 | 61 | ``` 62 | git rebase -i HEAD~3 63 | 64 | ``` 65 | 66 | 然后我们会看到如下界面: 67 | 68 | ![rebase示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/rebase-1.png) 69 | 70 | 上面未被注释的部分列出的是我们本次rebase操作包含的所有提交,下面注释部分是git为我们提供的命令说明。每一个commit id 前面的pick表示指令类型,git 为我们提供了以下几个命令: 71 | 72 | > pick:保留该commit(缩写:p) 73 | > 74 | > reword:保留该commit,但我需要修改该commit的注释(缩写:r) 75 | > 76 | > edit:保留该commit, 但我要停下来修改该提交(不仅仅修改注释)(缩写:e) 77 | > 78 | > squash:将该commit和前一个commit合并(缩写:s) 79 | > 80 | > fixup:将该commit和前一个commit合并,但我不要保留该提交的注释信息(缩写:f) 81 | > 82 | > exec:执行shell命令(缩写:x) 83 | > 84 | > drop:我要丢弃该commit(缩写:d) 85 | 86 | 87 | 根据我们的需求,我们将commit内容编辑如下: 88 | 89 | > pick d2cf1f9 fix: 第一次提交 90 | > 91 | > s 47971f6 fix: 第二次提交 92 | > 93 | > s fb28c8d fix: 第三次提交 94 | 95 | 上面的意思就是把第二次、第三次提交都合并到第一次提交上 96 | 97 | 然后`wq`保存退出后是注释修改界面: 98 | 99 | ![rebase示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/rebase-3.png) 100 | 101 | 102 | > 可以再浏览态 按下两个dd可以删除一行 103 | 104 | 最终的编辑效果如下: 105 | ![rebase示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/15_48_34__05_02_2018.jpg) 106 | 107 | 108 | 编辑完保存即可完成commit的合并了: 109 | 110 | ![rebase示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/15_49_16__05_02_2018.jpg) 111 | 112 | 最后查看`log`可以发下提交合并了 113 | 114 | ![rebase示意图](https://github.com/zuopf769/how_to_use_git/blob/master/images/15_49_42__05_02_2018.jpg) 115 | 116 | 117 | 118 | ## 5. 参考文献 119 | 120 | [rebase 用法小结](https://www.jianshu.com/p/4a8f4af4e803) 121 | 122 | -------------------------------------------------------------------------------- /利用tag管理项目版本号.md: -------------------------------------------------------------------------------- 1 | ## 利用tag管理项目版本号 2 | 3 | > [左鹏飞](https://github.com/zuopf769) 2017.12.04 4 | 5 | 6 | ### 1. 什么是tag?什么时候应该创建一个tag? 7 | 8 | 项目的版本管理中,每当一个release版本发布时,需要做一个记录,以便以后需要的时候能查找特定的版本,这时候就用到tag这个功能. 9 | 10 | Git中的tag指向一次commit的id,通常用来给开发分支做一个标记,如标记一个版本号。 11 | 12 | ### 2. tag和branch有什么区别? 13 | 14 | + branch是一个分支;tag是分支上的一个里程碑,一个点; 15 | + tag就是一个只读的branch;一般为每一个可发布的里程碑版本打一个tag; 16 | + 简单说比如branch有1.0,1.1等,其中1.0分支里可以有1.0.1,1.0.2这些tag; 17 | + tag就像是一个里程碑一个标志一个点; branch是一个新的征程一条线; 18 | + tag是静态的,branch要向前走; 19 | + 稳定版本备份用tag,新功能多人开发用branch(开发完成后merge到master)。 20 | 21 | 22 | ### 3. 相关操作命令 23 | 24 | #### 3.1 打标签 25 | 26 | ``` 27 | git tag -a 0.1.3 -m “Release version 0.1.3″ 28 | 29 | ``` 30 | > + git tag 是命令 31 | + -a 0.1.3是增加名为0.1.3的标签 32 | + -m 后面跟着的是标签的注释 33 | 34 | 打标签的操作发生在我们commit修改到本地仓库之后。 35 | 36 | 37 | #### 3.2 提交 38 | 39 | ``` 40 | git add . 41 | git commit -m “fixed some bugs” 42 | git tag -a 0.1.3 -m “Release version 0.1.3″ 43 | ``` 44 | 45 | #### 3.3 提交标签到远程服务器上 46 | 47 | ``` 48 | git push origin master 49 | git push origin --tags 50 | 51 | ``` 52 | 53 | > + –tags参数表示提交所有tag至服务器端,普通的git push origin master操作不会推送标签到服务器端。 54 | > + 如果指定特性的tag` git push origin [tagname] ` 55 | 56 | 57 | #### 3.4 删除标签的命令 58 | 59 | ``` 60 | git tag -d 0.1.3 61 | ``` 62 | 63 | #### 3. 5 删除远端服务器的标签 64 | 65 | ``` 66 | git push origin :refs/tags/0.1.3 67 | ``` 68 | 69 | ### 参考资料 70 | 71 | + [Git中tag的用法](http://blog.csdn.net/jeffasd/article/details/49863335) 72 | + [Git 基础 - 打标签](https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE) 73 | + [GitHub实战系列~发布版本之分支操作+Tag讲解](http://www.cnblogs.com/dunitian/p/5045132.html) -------------------------------------------------------------------------------- /如何安装git.md: -------------------------------------------------------------------------------- 1 | ## 如何安装git 2 | 3 | ### 配置账号 4 | 5 | 1)安装 [git客户端](http://www.git-scm.com/download/),生成`ssh-key`,如: 6 | 7 | ``` 8 | git config --global user.email 用户名@xx.com # 邮箱 9 | git config --global user.name 用户名 10 | ``` 11 | 12 | 2)配置密码(SSH公钥);注意:一个key不能被同时添加到多人的github账号下 13 | 14 | ``` 15 | #1)生成密钥,一路回车、用默认选项 16 | ssh-keygen -t rsa -C "你的邮箱" 17 | 18 | #2)复制到粘贴板 19 | cat ~/.ssh/id_rsa.pub | clip # Windows 20 | cat ~/.ssh/id_rsa.pub | pbcopy # MacOS 21 | 22 | #3)粘贴到github,在github右上角>个人设置>添加SSH Keys[注意:一定要把不可见的换行符去掉] 23 | ``` 24 | 25 | 3)配置命令行提示【非必须】;仅限Linux bash,Mac或Windows安装上文“安装方法”中推荐的客户端后就自动配置好了 26 | 27 | ``` 28 | #一键配置: 29 | #1) 自动补全:https://github.com/git/git/tree/master/contrib/completion 30 | #2) 命令行提示符:https://github.com/xtrementl/dev-bash-git-ps1 31 | ``` 32 | 33 | 4)编写代码 34 | 35 | 使用`git clone git@github.com:zuopf769/how-to-use-git.git`克隆出项目后,可修改,完成后可提交并推送,如: 36 | 37 | ``` 38 | git clone git@github.com:zuopf769/how-to-use-git.git 39 | cd XX 40 | vim readme.md 41 | ... 42 | git add -A 43 | git commit -m '更新说明' 44 | git push 45 | ``` 46 | 47 | 当推送(`push`)后,网站会自动更新为最新内容。 48 | 49 | > ps: 修改前最好`git pull`更新下,以防冲突,[git简单使用说明](http://www.bootcss.com/p/git-guide/) 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | --------------------------------------------------------------------------------