├── .gitignore ├── LICENSE ├── README.md ├── SPECIFY.md ├── chapter01 ├── 1.Git的介绍与安装说明.md ├── 2.Git的配置.md ├── 3.获取Git仓库.md ├── 4.git用于理解的图示-1.md └── gitpic.jpg ├── chapter02 ├── 1.Git 最基本流程.md ├── 2.Git 状态查看.md ├── 3.Git 状态重置 或者 回滚.md ├── 4.Git Diff 差异分析.md ├── 5.Git 文件删除、重命名.md └── 6.Git之gitignore的使用.md ├── chapter03 ├── 1.Git 分支管理.md ├── 2.情景1: Git的分支处理.md ├── 3.Git分支图示.md └── gitpic2.jpg ├── chapter04 ├── 1.Git 远程分支管理.md ├── 2.Git 本地与远程同步操作.md ├── 3.Git 远程分支关联.md ├── 4.Git对版本库的文件取消track.md └── 5.Git远程其他操作.md └── pdf_release ├── 【官方】Git中文文档.pdf └── 【第一版】Git笔记.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright (C) 2020 LEOBOD (leobod@eside.cn) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitGuide 2 | 3 | ## 标识 4 | ![1](https://img.shields.io/badge/LICENSE-Apache%202.0-blue.svg) ![2](https://img.shields.io/badge/CN-ESIDE-orange.svg?longCache=true) ![3](https://img.shields.io/badge/VERSION-v2.0.0-red.svg?longCache=true) ![4](https://img.shields.io/badge/AUTHOR-LEOBOD-green.svg?longCache=true) 5 | 6 | 7 | 8 | ## 说明 9 | 10 | + 作者:leobod 11 | + 创建时间: 2019-02-13 12 | + 一版修改: 2019-10-22 13 | + 二版修改: 2020-10-10 14 | 15 | 16 | 17 | ## 文件结构 18 | + chapter01 包括: 19 | + [1.Git的介绍与安装说明](./chapter01/) 20 | + [2.Git的配置](./chapter01/) 21 | + [3.获取Git仓库](./chapter01/) 22 | + [4.Git用于理解的图示](./chapter01/) 23 | + chapter02 包括: 24 | + [1.Git 最基本流程](./chapter02/) 25 | + [2.Git 状态查看](./chapter02/) 26 | + [3.Git 状态重置 或者 回滚](./chapter02/) 27 | + [4.Git Diff 差异分析](./chapter02/) 28 | + [5.Git 文件删除、重命名](./chapter02/) 29 | + [6.Git之gitignore的使用](./chapter02/) 30 | + chapter03 包括: 31 | + [1.Git 分支管理](./chapter03/) 32 | + [2.Git的分支处理](./chapter03/) 33 | + [3.Git分支处理图示](./chapter03/) 34 | + chapter04 包括: 35 | + [1.Git 远程分支管理](./chapter04/) 36 | + [2.Git 本地与远程同步操作](./chapter04/) 37 | + [3.Git 远程分支关联](./chapter04/) 38 | + [4.Git对版本库的文件取消track](./chapter04/) 39 | + [5.Git远程其他操作](./chapter04/) 40 | + [待补充] 41 | 42 | 43 | 44 | ## 内容组织方式 45 | 46 | + 单词 ———————— 用到哪些关键词 47 | + 语法 ———————— 关键词的语法,比如有哪些参数 48 | + 语义 ———————— 结合具体的一些情况,如何组织语法,如何达到使用Git的目的 49 | + 情景 ———————— 用于补充具体的场景,或者具体情况下 有哪些可能的操作 50 | 51 | 52 | 53 | #### 参与贡献 54 | 55 | 发送邮件到: join@eside.cn 56 | 57 | 或者发送到: [leobod@eside.cn](mailto://leobod@eside.cn) 58 | 59 | #### 补充 60 | 61 | 1. 使用 Readme.md 来做首页说明。 62 | 2. 使用LICENSE用来存储使用的许可原文 63 | 3. 使用SPECIFY.md来对许可进一步补充,如果有的话。 64 | 4. LEOBOD 的个人主页。 [www.leobod.cn](https://www.leobod.cn) 65 | 5. ESIDE.CN 欢迎所有志同道合的伙伴们一起交流。 [www.eside.cn](https://www.eside.cn) -------------------------------------------------------------------------------- /SPECIFY.md: -------------------------------------------------------------------------------- 1 | ## Version: English 2 | 3 | ### Basic LICENSE 4 | 5 | ``` 6 | Copyright (C) 2020 LEOBOD (leobod@eside.cn) 7 | Unless otherwise specified. Licensed under the Apache License, Version 2.0 (the "License"); 8 | You may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 10 | Or you can view the LICENSE file under the current project (Apache LICENSE, Version 2.0) 11 | 12 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 13 | an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and limitations under the License. 15 | ``` 16 | 17 | ### SPECIFY 18 | 19 | ``` 20 | 无 21 | ``` 22 | 23 | 24 | ## 版本: 中文版 25 | 26 | ### 基本协议 27 | 28 | ``` 29 | 版权所有 (C) 2020 LEOBOD (leobod@eside.cn) 30 | 31 | 除非另有说明,使用Apache许可证2.0版本(“许可证”)授权;除非符合许可证规定,否则您不能使用此文件。 32 | 您可以在以下网址获得许可证的副本http://www.apache.org/licenses/LICENSE-2.0 33 | 或者你可以查看当前项目下的LICENSE文件(Apache License, Version 2.0的原文件) 34 | 35 | 除非适用法律要求或书面同意,否则所有材料必须在许可下基于“现状”发布的。 36 | 对于使用材料而产生的不良影响,概不负责。 37 | 请仔细参阅许可证,了解在许可证下明确的权利与限制。 38 | ``` 39 | 40 | ### 特别说明 41 | 42 | ``` 43 | 无 44 | ``` 45 | -------------------------------------------------------------------------------- /chapter01/1.Git的介绍与安装说明.md: -------------------------------------------------------------------------------- 1 | ## Git的介绍 2 | 3 | [toc] 4 | 5 | 6 | 7 | ### 什么是Git 8 | 9 | Git 是一个开源的分布式版本控制系统。 10 | 11 | + 分布式 : 12 | + 你的文件可以存放在多个不同的系统(或者位置),相互之间来自于一个 原本,单个副本修改,不影响其他副本。 13 | + 但是可以通过从一个指定地方(比如Github,或者自己构建的gitlab)上传与拉取来获得更新。 14 | 15 | + 版本控制系统: 顾名思义 16 | + 相比于 集中式版本控制系统,他更小巧,更快捷,更方便。 17 | + 不依赖中央服务器,本质上继承了他的创造者的 一切皆文件的想法。 18 | + 其实他就是你随处可以带走的文件,只不过加了一套逻辑,可以配合Git来控制,从而进行版本控制。 19 | 20 | 21 | 22 | ### Git的安装 23 | 24 | #### Linux下安装 25 | 26 | ```shell 27 | Linux 下使用如下命令安装 28 | sudo yum install git //适用于 RedHat 系的 Linux 29 | 或者 30 | sudo apt-get install git //适用于 Ubuntu 系的 Linux 31 | 或者 32 | sudo apt-get install git-core //适用于 老版本 Ubuntu 系的 Linux 33 | ``` 34 | 35 | 一般情况下当下的Linux都自带了 git 36 | 37 | 对于更多Linux的安装方法参考 38 | 39 | #### Mac下安装 40 | 41 | + 使用homebrew安装 42 | 43 | ``` 44 | brew install git 45 | ``` 46 | 47 | + 二进制安装程序。 48 | 49 | 官方维护的 OSX Git 安装程序可以在 Git 官方网站下载,网址为 50 | 51 | #### Windows下安装 52 | 53 | 请直接前往 [git官网](https://git-scm.com/) 下载,辅之以图形界面工具(可以考虑fork),另外终端操作以后值得学习。 54 | 55 | 在win10 1709版本以上的,可以辅之使用 windows subsystem的Linux来配合使用 56 | 57 | 58 | 59 | ### 查看是否有git或者安装是否成功 60 | 61 | #### 查看git版本 62 | 63 | ``` 64 | git --version 65 | ``` 66 | 67 | 68 | 69 | 70 | 71 | ## 参考说明 72 | 73 | > 本文部分内容参考:[Git官方指南--1.5 起步 - 安装 Git](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git) -------------------------------------------------------------------------------- /chapter01/2.Git的配置.md: -------------------------------------------------------------------------------- 1 | ## Git的配置 2 | 3 | [toc] 4 | 5 | 6 | 7 | ### 单词 8 | 9 | * `config` : 设置与查看 Git 外观和行为的配置变量 10 | * `--system` : 11 | * 对应`/etc/gitconfig` 文件,包含系统上每一个用户及他们仓库的通用配置。 12 | * `--global` : 13 | * 对应`~/.gitconfig` 或 `~/.config/git/config` 文件,只针对当前用户。 14 | * `--local` : 15 | * 对应 `.git/config`,即当前使用仓库的 Git 目录中的 `config` 文件 16 | * `--list` : 列举配置 17 | * 每一个级别会覆盖上一级别的配置 18 | 19 | 20 | 21 | ### 语法 22 | 23 | ```git 24 | git config --local //当前Git工作区的配置 25 | git config --global //全局Git工作区的配置 26 | git config --system //系统Git工作区的配置 27 | 28 | git config --list //Git配置列举 29 | git config --unset --local //Git配置重置 30 | ``` 31 | 32 | 33 | 34 | ### 语义 35 | 36 | #### Git最小化配置 37 | 38 | + 配置用户名与邮箱 39 | 40 | ```git 41 | git config --global user.name 'name' //配置全局的 名称 42 | git config --global user.email 'email@address' //配置全局的 邮件地址 43 | 44 | // 比如 git config --global user.name 'leo' 45 | // 比如 git config --global user.email 'leobod@eside.cn' 46 | ``` 47 | 48 | + git 的 配置 分为 49 | + 当前工作区 `--local` 50 | + 当前工作区只对 单个Git工作区 有效 51 | + 全局 `--global` 52 | + 全局配置,对当前所有 Git有效, 53 | + 但是当工作区本身有 local 配置时,以 local 为准 54 | + 系统 `--system` 55 | 56 | 一般为了方便都是配置的 全局(global)配置,若没有配置,后期用户在使用git 时会提示要求你配置 57 | 58 | #### Git 配置查看 59 | 60 | ```git 61 | git config --list 62 | git config --list --global //--排名不分先后 63 | git config --list --local 64 | 65 | git config --global user.name //查看单条配置 66 | git config --global user.email 67 | ``` 68 | 69 | #### 查看配置及所在的文件 70 | 71 | ``` 72 | git config --list --show-origin 73 | ``` 74 | 75 | #### 配置默认文本编辑器 76 | 77 | ``` 78 | git config --global core.editor vim 79 | ``` 80 | 81 | 82 | 83 | 84 | 85 | ## 补充说明 86 | 87 | 88 | 89 | 90 | 91 | ## 参考说明 92 | 93 | > 本文部分内容参考:[Git官方指南--1.6 起步 - 初次运行 Git 前的配置](https://git-scm.com/book/zh/v2/%E8%B5%B7%E6%AD%A5-%E5%88%9D%E6%AC%A1%E8%BF%90%E8%A1%8C-Git-%E5%89%8D%E7%9A%84%E9%85%8D%E7%BD%AE) 94 | 95 | -------------------------------------------------------------------------------- /chapter01/3.获取Git仓库.md: -------------------------------------------------------------------------------- 1 | ## 获取Git仓库 2 | 3 | 4 | 5 | ### 单词 6 | 7 | + `clone` 8 | 9 | 10 | 11 | ### 语法 12 | 13 | ``` 14 | git clone
15 | ``` 16 | 17 | 18 | 19 | ### 语义 20 | 21 | #### 克隆一个仓库 22 | 23 | + 最简洁指令 24 | 25 | ``` 26 | git clone https://gitee.com/leobod/GitGuide.git 27 | 或者也可以使用 git:// 协议或者使用 SSH 传输协议 28 | git clone git@gitee.com:leobod/GitGuide.git 29 | ``` 30 | 31 | + 克隆并指定文件名 32 | 33 | ``` 34 | git clone https://gitee.com/leobod/GitGuide.git GGuide 35 | ``` 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /chapter01/4.git用于理解的图示-1.md: -------------------------------------------------------------------------------- 1 | ## git用于理解的图示-1 2 | 3 | [toc] 4 | 5 | 6 | 7 | ### 工作区、暂存区、版本与远程库 8 | 9 | ![](./gitpic.jpg) 10 | 11 | -------------------------------------------------------------------------------- /chapter01/gitpic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leobod/GitGuide/702c3cdbbf394f20f68fd5062d599b08bb403d73/chapter01/gitpic.jpg -------------------------------------------------------------------------------- /chapter02/1.Git 最基本流程.md: -------------------------------------------------------------------------------- 1 | # Git 基础 2 | 3 | ## 单词 4 | 5 | + init 6 | + add 7 | + commit 8 | 9 | ## 语法 10 | 11 | ### Git的初始化 12 | 13 | ```git 14 | git init //将当前目录 初始化成 Git仓库 15 | git init //在当前目录下 创建 project_name 的目录 并初始化成 Git仓库 16 | ``` 17 | 18 | ### Git添加文件到暂存区 19 | 20 | ```git 21 | git add //Git 初始化后 使用 add 来 将file添加到暂存区 22 | git add -u //Git 添加 中所有tracked文件中被修改过或已删除文件的信息 23 | git add -A //Git 添加 所有文件中被修改过或已删除文件的信息 和 未追踪的文件 24 | git add -h //Git add 帮助说明 25 | ``` 26 | 27 | ### Git 提交文件到 版本库 28 | 29 | ```git 30 | git commit -m 'tips_message' //Git 将暂存区修改 提交到版本库 并给commit标识 提示语 31 | git commit -am 'tips_message' //Git 将所有修改的文件 提交到版本库,不管是否添加到暂存区 32 | 等同于 33 | git add -a 34 | git commit -m 'tips_message' 35 | 36 | git commit -h //Git commit 帮助信息 37 | git commit --amend //将最近的修改 附加到 最近一次的 commit 上 38 | ``` 39 | 40 | 41 | 42 | ## 语义 43 | 44 | ### 创建一个Git仓库,初始化并提交一些commit 45 | 46 | ```git 47 | cd /path/……/project_01 //shell 下切换到 指定目录(根据具体情况) 48 | git init //Git 仓库初始化 49 | vi README.md //vi 新建或编辑一个 文件 50 | git add README.md //添加 README.md 到 暂存区 51 | git commit -m 'Write a README to introduce the project!' //提交修改到 版本库 52 | ``` 53 | 54 | ```git 55 | 或者 56 | cd /path/……/ //shell 下切换到 指定目录(根据具体情况) 57 | git init project_02 //Git 仓库初始化 58 | vi README.md //vi 新建或编辑一个 文件 59 | git commit -am 'Write a README to introduce the project!' //提交修改到 版本库 60 | ``` 61 | 62 | -------------------------------------------------------------------------------- /chapter02/2.Git 状态查看.md: -------------------------------------------------------------------------------- 1 | # Git 状态查看 2 | 3 | ## 单词 4 | 5 | + version 6 | + status 7 | + log 8 | 9 | ## 语法 10 | 11 | ### 查看Git版本 12 | 13 | ```git 14 | git --version 15 | ``` 16 | 17 | ### 查看 工作区 暂存区文件状态 18 | 19 | ```git 20 | git status 21 | ``` 22 | 23 | ### 查看 commit 历史记录 24 | 25 | ```git 26 | git log 27 | --oneline //一条 commit 在一行显示 28 | --graph //显示 路径 线条 29 | ``` 30 | 31 | 32 | 33 | 34 | 35 | ## 语义 36 | 37 | ### 查看 本机git 版本号 38 | 39 | ```git 40 | git --version 41 | ``` 42 | 43 | 结果: 44 | 45 | git version 2.17.1 46 | 47 | 48 | 49 | ### 查看 工作区 暂存区文件状态 50 | 51 | ```git 52 | git status 53 | ``` 54 | 55 | 结果1: 56 | 57 | On branch master 58 | 59 | 60 | Your branch is up to date with 'origin/master'. 61 | 62 | nothing to commit, working tree clean 63 | 64 | // 当前 处于 master 分支。分支具体请查看分支管理 65 | 66 | // 你的分支 已经是最新的了, 包含了远端分支,若未连接Github 一般无这条提示 67 | 68 | // 没有什么克提交的, 工作区 暂存区 无变化 69 | 70 | 71 | 72 | 结果2: 73 | 74 | On branch master 75 | 76 | No commits yet 77 | 78 | Untracked files: 79 | (use "git add ..." to include in what will be committed) 80 | 81 | README.md 82 | 83 | nothing added to commit but untracked files present (use "git add" to track) 84 | 85 | // 当前分支 master 86 | 87 | // 还没有 commit 88 | 89 | //为追踪的文件 有 README.md 可以使用 git add 来添加 到 暂存区 90 | 91 | 92 | 93 | 结果3: 94 | 95 | On branch master 96 | 97 | No commits yet 98 | 99 | Changes to be committed: 100 | (use "git rm --cached ..." to unstage) 101 | 102 | new file: README.md 103 | 104 | // 当前分支 master 105 | 106 | // 还没有 commit 107 | 108 | //新的改变 等待提交, 如果想 取消,可以使用 git rm --cached 从 暂存区中移除 指定文件 109 | 110 | // 若没有问题 在合适的时候 可以 使用 git commit 来提交到 版本库 111 | 112 | 113 | 114 | ### 查看 commit 的日志 方式1 115 | 116 | ```git 117 | git log 118 | ``` 119 | 120 | 结果: 121 | 122 | commit 58a8145557cab8a08eedc0877f6fabe419fa84d9 (HEAD -> master, origin/master, origin/c1, origin/HEAD, c1) 123 | Author: leobod <13952348337@sina.cn> 124 | Date: Fri Feb 8 20:56:01 2019 +0800 125 | 126 | Git的介绍与安装,以及简单配置 127 | 128 | commit efddeada1f93ba9a822ac208cfdf4915b6d406c2 129 | Author: leobod <13952348337@sina.cn> 130 | Date: Fri Feb 8 19:10:43 2019 +0800 131 | 132 | 修改GitGuide的README.md,来说明如如何学习与记录Git的使用 133 | 134 | commit 920f45c5909c33b49f0da5eba413c02d8d85faee 135 | Author: leobod <13952348337@sina.cn> 136 | Date: Fri Feb 8 15:52:09 2019 +0800 137 | 138 | Git 使用指南的 书写格式 139 | 140 | commit cb5b26d8271c1fe4871094b66b8f7469e3c59859 141 | Author: 差三岁Lee <13952348337@sina.cn> 142 | Date: Thu Jan 10 13:54:05 2019 +0800 143 | 144 | Initial commit 145 | 146 | 147 | 148 | // commit 后跟 提交的 hash 值,后期可以 使用 前 7位值来定位, 也可以多选 几位, 一般 7位就够 149 | 150 | //Author 显示 commit 的提交是谁,以及邮箱号,用于对 commit 有问题 或疑问时,责任到人,一般在本机都是 用户 在 git config 处设置的值,如果没有设置,每次提交时 都会 提示要求输入 151 | 152 | // Date 后跟 这个提交的日期 153 | 154 | ### 查看 commit 的日志 方式2 155 | 156 | ```git 157 | git log --oneline --graph 158 | // --oneline与 --graph 可以单独使用 159 | ``` 160 | 161 | 结果: 162 | 163 | * 58a8145 (HEAD -> master, origin/master, origin/c1, origin/HEAD, c1) Git的介绍与安装,以及简单配置 164 | * efddead 修改GitGuide的README.md,来说明如如何学习与记录Git的使用 165 | * 920f45c Git 使用指南的 书写格式 166 | * cb5b26d Initial commit 167 | 168 | 169 | 170 | //一条 commit 缩在 一行 前7位显示 commit的 hash值,后面跟 <分支名称> 在跟 171 | 172 | * 号 其实 在终端一般 显示为 * ,在图形端一般是 平滑的线条连接, 173 | 174 | 此处 分支都在一条线上,理论上多分支时,可以向树 (或者 森林)一样延展,多数情况下是树,一般不建议搞成 <森林> 175 | 176 | 何为 树 何为 森林 请 查看数据结构 树的相关内容。 -------------------------------------------------------------------------------- /chapter02/3.Git 状态重置 或者 回滚.md: -------------------------------------------------------------------------------- 1 | # Git 状态重置 或者 回滚 2 | 3 | ## 单词 4 | 5 | + reset 6 | + checkout 7 | + HEAD HEAD^ HEAD~n 8 | 9 | ## 语法 10 | 11 | ### git 工作区还原到 暂存区的状态,也就是说 取消最近新添加的文件修改 12 | 13 | ```git 14 | git checkout . //还原工作区 <所有> 文件 为暂存区状态暂存区状态 15 | 16 | git checkout -- filename //还原工作区 <指定> 文件 为暂存区状态暂存区状态 17 | 18 | 补充说明:暂存区状态(最近一次commit 或者 暂存区回滚到的 commit 状态) 19 | ``` 20 | 21 | ### git暂存区 恢复到 commit 状态 22 | 23 | ```git 24 | git reset HEAD // 恢复暂存区到 HEAD 指针指向的位置 25 | git reset HEAD^ // 恢复暂存区到 HEAD 的上一次 commit 26 | git reset HEAD~4 // 恢复暂存区到 HEAD 的上第4次 commit 27 | 28 | git reset // 恢复暂存区到 指定hash commit处 29 | 30 | git reset 缺省值为 mixed //将HEAD reset 没有修改 工作区 但是修改了 暂存区 31 | 32 | git reset --soft //将HEAD reset 没有修改 工作区 与 暂存区 33 | 34 | git reset --hard //将HEAD reset 同时修改工作区与暂存区 35 | ``` 36 | 37 | git reset 后 git log 只显示到 HEAD commit 处,以往的不显示,但是 可以到 项目的 `.git/logs/refs`中去寻找 一般记录保存 30天 38 | 39 | 找到后可以 使用 git reset ,来重置 40 | 41 | 42 | 43 | ## 语义 44 | 45 | ### 单线型 版本迭代演进 与回滚演示 46 | 47 | ### 演示前的准备 48 | 49 | 1. `git init Test` 初始化 一个Test 用于 git 演示 50 | 51 | 2. 建立 `hello.c`文件 用于版本迭代 52 | 53 | 3. `git ad hello.c` 且 `git commit -m ‘Write a Hello World C Language file'` 54 | 55 | 4. `git log --oneline` 结果: 56 | 57 | ``` 58 | b2e1368 Write a Hello World C Language filWrite a Hello World C Language fil 59 | ``` 60 | 61 | 5. `vi hello.c` 在文件里面 return 0 前 补充 getchar() 并提交 62 | 63 | 6. `git log --oneline` 结果: 64 | 65 | eb96dee At the end insert getchar() to make a wait 66 | b2e1368 Write a Hello World C Language fil 67 | 68 | 7. `vi hello.c` 在文件里面 补上 // Author: XXXX 提交 69 | 70 | 8. `git log --oneline` 结果: 71 | 72 | ``` 73 | 550f417 (HEAD -> master) insert author information into the file 74 | eb96dee At the end insert getchar() to make a wait 75 | b2e1368 Write a Hello World C Language fil 76 | ``` 77 | 78 | --- 79 | 80 | --- 81 | 82 | ### 修改开始 83 | 84 | 代码最初为: 85 | 86 | ``` 87 | #include 'stido.h' 88 | int main() { 89 | printf('Hello World! \n'); 90 | return 0; 91 | } 92 | ``` 93 | 94 | 95 | 96 | 1. 当前 hello.c 源码 如下: 97 | 98 | 2. ``` 99 | #include 'stido.h' 100 | // Author: Leobod 101 | int main() { 102 | printf('Hello World! \n'); 103 | getchar(); 104 | return 0; 105 | } 106 | ``` 107 | 108 | 3. 修改后 109 | 110 | 4. ``` 111 | #include 'stido.h' 112 | // Author: Leobod 113 | // Description: A C language demo 114 | int main() { 115 | printf('Hello World! \n'); 116 | getchar(); 117 | return 0; 118 | } 119 | ``` 120 | 121 | #### 情况1 122 | 123 | 若 使用 `git checkout .` 或者 `git checkout -- Hello.c` 后 恢复到 2处样式 124 | 125 | #### 情况2 126 | 127 | 若 使用 `git reset --hard b2e1368` 恢复到 代码最初样子 且 工作区 暂存区代码都一样 128 | 129 | `git log ` 为 130 | 131 | ``` 132 | b2e1368 Write a Hello World C Language fil 133 | ``` 134 | 135 | 可以使用 `git reset --hard 550f417` 返回 最后一次修改状态 136 | 137 | 找不到 hash 请前往 `.git/logs/refs` 中寻找 138 | 139 | #### 情况3 140 | 141 | 若使用 `git reset b2e1368` 工作区 代码 仍为 4处 样式, 暂存区与版本库为 代码最初样式 142 | 143 | 此时 使用 `git status` 可以发现提示 144 | 145 | 若想 工作区也 还原 多执行一步 `git checkout .` 146 | 147 | 回到 最新状态 依然是 `git reset 550f417` 148 | 149 | 此处 `550f417` 对应最后一次commit的 hash 值 150 | 151 | 152 | 153 | 154 | 155 | > 本文部分内容参考引用了 [Domon-Git Reset 三种模式](https://www.domon.cn/2018/09/06/Git-reset-used-in-coding/) -------------------------------------------------------------------------------- /chapter02/4.Git Diff 差异分析.md: -------------------------------------------------------------------------------- 1 | # Git Diff 差异分析 2 | 3 | ## 虽然命名交 Git diff 但是实际上 diff 可以是一个单独的工具,专门用来进行 文本比较 4 | 5 | ## diff 是Linux 自带的命令,同样 git 中也集成了这个命令 6 | 7 | 命令格式: 8 | 9 | `diff <参数> <文件1或目录1> <文件2或目录2>` 10 | 11 | 详情可以参考 [菜鸟教程--Linux diff](http://www.runoob.com/linux/linux-comm-diff.html) 或者参考 [博客园中的信息](https://www.cnblogs.com/newcaoguo/p/5896390.html) 12 | 13 | 14 | 15 | ## git 的 diff 16 | 17 | ```git 18 | git diff 谁 与 谁 比较 19 | git diff --cached //省略HEAD HEAD与暂存区比较 20 | git diff //工作区 与暂存区 比较 21 | =diff --git a/ b/ 22 | 23 | 假定:HEAD、缓存区、工作区中的readme.md文件内容均不相同。 24 | git diff HEAD -- readme.md //工作区 <===> HEAD 25 | git diff -- readme.md //工作区 <===> 缓存区 26 | git diff --cached -- readme.md //缓存区 <===> HEAD 27 | 28 | git diff -- //分支 指定文件 比较 29 | ``` 30 | 31 | 具体可以参考 [Git-diff](https://www.yiibai.com/git/git_diff.html) -------------------------------------------------------------------------------- /chapter02/5.Git 文件删除、重命名.md: -------------------------------------------------------------------------------- 1 | # Git 文件删除、重命名 2 | 3 | ## 单词 4 | 5 | + rm 6 | + mv 7 | 8 | ## 语法 9 | 10 | ```git 11 | git rm file //删除指定文件,同时 实现 rm 12 | git mv //修改 Git仓库 里面的文件名,会同时实现 mv 13 | ``` 14 | 15 | -------------------------------------------------------------------------------- /chapter02/6.Git之gitignore的使用.md: -------------------------------------------------------------------------------- 1 | ## `.gitignore`的使用 2 | 3 | [toc] 4 | 5 | 6 | 7 | ### .gitignore配置文件规则 8 | 9 | 在 .gitingore 文件中,遵循相应的语法,在每一行指定一个忽略规则。如: 10 | 11 | ``` 12 | *.log 13 | *.temp 14 | /vendor 15 | ``` 16 | 17 | ### 定义全局的 .gitignore 文件 18 | 19 | 除了可以在项目中定义 .gitignore 文件外,还可以设置全局的 git .gitignore 文件来管理所有Git项目的行为。 20 | 21 | ``` 22 | git config --global core.excludesfile ~/.gitignore 23 | ``` 24 | 25 | ### Git 忽略规则优先级 26 | 27 | 在 .gitingore 文件中,每一行指定一个忽略规则,Git 检查忽略规则的时候有多个来源 28 | 优先级如下(由高到低): 29 | 30 | + 从命令行中读取可用的忽略规则 31 | + 当前目录定义的规则 32 | + 父级目录定义的规则,依次地推 33 | + $GIT_DIR/info/exclude 文件中定义的规则 34 | + core.excludesfile中定义的全局规则 35 | 36 | ### Git 忽略规则匹配语法 37 | 38 | 在 .gitignore 文件中,每一行的忽略规则的语法如下: 39 | 40 | + `空格` 不匹配任意文件,可作为分隔符,可用反斜杠转义 41 | + `# 开头` 的模式标识注释,可以使用反斜杠进行转义 42 | + `! 开头` 的模式标识否定,该文件将会再次被包含, 43 | + 如果排除了该文件的父级目录,则使用 ! 也不会再次被包含。可以使用反斜杠进行转义 44 | + `/ 结束` 的模式只匹配文件夹以及在该文件夹路径下的内容,但是不匹配该文件 45 | + `/ 开始` 的模式匹配项目跟目录 46 | + 如果一个模式不包含斜杠,则它匹配相对于当前 .gitignore 文件路径的内容,如果该模式不在 .gitignore 文件中,则相对于项目根目录 47 | + `**匹配` 多级目录,可在开始,中间,结束 48 | + `?` 通用匹配单个字符 49 | + `[]` 通用匹配单个字符列表 50 | 51 | 52 | 53 | ### .gitignore常用规则 54 | 55 | #### 常用匹配示例: 56 | 57 | ``` 58 | bin/: 忽略当前路径下的bin文件夹,该文件夹下的所有内容都会被忽略,不忽略 bin 文件 59 | /bin: 忽略根目录下的bin文件 60 | /*.c: 忽略 cat.c,不忽略 build/cat.c 61 | debug/*.obj: 忽略 debug/io.obj,不忽略 debug/common/io.obj 和 tools/debug/io.obj 62 | **/foo: 忽略/foo, a/foo, a/b/foo等 63 | a/**/b: 忽略a/b, a/x/b, a/x/y/b等 64 | !/bin/run.sh: 不忽略 bin 目录下的 run.sh 文件 65 | *.log: 忽略所有 .log 文件 66 | config.php: 忽略当前路径的 config.php 文件 67 | ``` 68 | 69 | 70 | 71 | #### .gitignore常用规则-JAVA 72 | 73 | ``` 74 | # Operating System Files 75 | 76 | *.DS_Store 77 | Thumbs.db 78 | *.sw? 79 | .#* 80 | *# 81 | *~ 82 | *.sublime-* 83 | 84 | # Build Artifacts 85 | 86 | .gradle/ 87 | build/ 88 | target/ 89 | bin/ 90 | dependency-reduced-pom.xml 91 | 92 | # Eclipse Project Files 93 | 94 | .classpath 95 | .project 96 | .settings/ 97 | 98 | # IntelliJ IDEA Files 99 | 100 | *.iml 101 | *.ipr 102 | *.iws 103 | *.idea 104 | ``` 105 | 106 | 107 | 108 | #### .ignore规则配置-C++ 109 | 110 | ``` 111 | # User ================================ 112 | # 用户自定义的其他忽略文件 113 | 114 | # Clion ================================ 115 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 116 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 117 | 118 | # User-specific stuff 119 | .idea/**/workspace.xml 120 | .idea/**/tasks.xml 121 | .idea/**/usage.statistics.xml 122 | .idea/**/dictionaries 123 | .idea/**/shelf 124 | 125 | # Generated files 126 | .idea/**/contentModel.xml 127 | 128 | # Sensitive or high-churn files 129 | .idea/**/dataSources/ 130 | .idea/**/dataSources.ids 131 | .idea/**/dataSources.local.xml 132 | .idea/**/sqlDataSources.xml 133 | .idea/**/dynamic.xml 134 | .idea/**/uiDesigner.xml 135 | .idea/**/dbnavigator.xml 136 | 137 | # Gradle 138 | .idea/**/gradle.xml 139 | .idea/**/libraries 140 | 141 | # Gradle and Maven with auto-import 142 | # When using Gradle or Maven with auto-import, you should exclude module files, 143 | # since they will be recreated, and may cause churn. Uncomment if using 144 | # auto-import. 145 | # .idea/modules.xml 146 | # .idea/*.iml 147 | # .idea/modules 148 | # *.iml 149 | # *.ipr 150 | 151 | # CMake 152 | cmake-build-*/ 153 | 154 | # Mongo Explorer plugin 155 | .idea/**/mongoSettings.xml 156 | 157 | # File-based project format 158 | *.iws 159 | 160 | # IntelliJ 161 | out/ 162 | 163 | # mpeltonen/sbt-idea plugin 164 | .idea_modules/ 165 | 166 | # JIRA plugin 167 | atlassian-ide-plugin.xml 168 | 169 | # Cursive Clojure plugin 170 | .idea/replstate.xml 171 | 172 | # Crashlytics plugin (for Android Studio and IntelliJ) 173 | com_crashlytics_export_strings.xml 174 | crashlytics.properties 175 | crashlytics-build.properties 176 | fabric.properties 177 | 178 | # Editor-based Rest Client 179 | .idea/httpRequests 180 | 181 | # Android studio 3.1+ serialized cache file 182 | .idea/caches/build_file_checksums.ser 183 | 184 | # vscode ================================ 185 | .vscode/* 186 | !.vscode/settings.json 187 | !.vscode/tasks.json 188 | !.vscode/launch.json 189 | !.vscode/extensions.json 190 | 191 | # C++ ================================ 192 | Prerequisites 193 | *.d 194 | 195 | # Compiled Object files 196 | *.slo 197 | *.lo 198 | *.o 199 | *.obj 200 | 201 | # Precompiled Headers 202 | *.gch 203 | *.pch 204 | 205 | # Compiled Dynamic libraries 206 | *.so 207 | *.dylib 208 | *.dll 209 | 210 | # Fortran module files 211 | *.mod 212 | *.smod 213 | 214 | # Compiled Static libraries 215 | *.lai 216 | *.la 217 | *.a 218 | *.lib 219 | 220 | # Executables 221 | *.exe 222 | *.out 223 | *.app 224 | 225 | 226 | # CMake ================================ 227 | bin/ 228 | build/ 229 | CMakeLists.txt.user 230 | CMakeCache.txt 231 | CMakeFiles 232 | CMakeScripts 233 | Testing 234 | Makefile 235 | cmake_install.cmake 236 | install_manifest.txt 237 | compile_commands.json 238 | CTestTestfile.cmake 239 | ``` 240 | 241 | -------------------------------------------------------------------------------- /chapter03/1.Git 分支管理.md: -------------------------------------------------------------------------------- 1 | # Git 分支管理 2 | 3 | ## 单词 4 | 5 | + branch 6 | + checkout 7 | + merge 8 | 9 | ## 语法 10 | 11 | ### Git 分支建立与切换 12 | 13 | ```git 14 | git branch //建立分支 15 | git checkout //切换到 branch_name 的分支 16 | 17 | 等同于 18 | git checkout -b //新建 并切换到 branch_name 的分支 19 | ``` 20 | 21 | ### Git 已有分支查看 22 | 23 | ```git 24 | git branch //查看分支 25 | git branch -v //查看每一个分支的最后一次提交 26 | git branch -a //查看所有分支 ,包含 远端分支 27 | git branch -av //查看所有分支 以及 最后一次提交 28 | ``` 29 | 30 | ### Git分支删除 31 | 32 | ```git 33 | git branch -d //删除 指定分支 34 | git branch -D //强制删除 指定分支,删除分支并丢掉所做的修改 35 | ``` 36 | 37 | ### Git 分支合并 38 | 39 | ```git 40 | git checkout master //切换到分支 master 41 | git merge //将指定分支 的修改 合并到 master 上 42 | ``` 43 | 44 | 45 | 46 | ## 语义 47 | 48 | -------------------------------------------------------------------------------- /chapter03/2.情景1: Git的分支处理.md: -------------------------------------------------------------------------------- 1 | # 情景1: Git的常见分支处理方案 2 | 3 | ## 前置状态 4 | 5 | 现在有一个 Git仓库, 里面有 README.txt 文件 和 description.txt 文件 6 | 7 | README.txt 文件内容 8 | 9 | ```txt 10 | This is the first line in the README.txt 11 | ``` 12 | 13 | description.txt 文件为空 14 | 15 | 有如下分支 16 | 17 | + master 18 | + feature 19 | + develop 20 | 21 | 22 | 23 | ## 操作方案1--不同分支处理了同一个文件,合并时产生冲突的处理 24 | 25 | 开始时 master <==> feature <==> develop (3个分支处于同一处) 26 | 27 | 28 | 29 | 切换到 feature 分支 30 | 31 | ​ 修改 read.txt 文件为 32 | 33 | ``` txt 34 | This is the first in the read.txt 35 | in the feature branch 36 | ``` 37 | 38 | commit 2 39 | 40 | ​ commit1 commit2 41 | 42 | 修改后 init ----------> master(develop)----------> feature 43 | 44 | ​ 45 | 46 | 切换到 develop 分支,并保证工作区 与 初始状态一样 47 | 48 | ​ 修改 read.txt 文件为 49 | 50 | ```txt 51 | This is the first in the read.txt 52 | In the develop branch 53 | ``` 54 | 55 | commit3 56 | 57 | ​ commit1 58 | 59 | 修改后 init --------> master--------> feature[处于commit2] 60 | 61 | ​ | 62 | 63 | ​ | 64 | 65 | ​ ----------------> develop[处于commit3] 66 | 67 | 68 | 69 | 最后 切换到 master分支,并保证 工作区与 版本库一致(也就是最初始状态) 70 | 71 | 此处先 合并 develop 后合并feature (也可以 先合并feature后合并 develop 效果一样) 72 | 73 | git merge feature 74 | 75 | git merge develop 76 | 77 | 出现冲突,处理冲突文件 read.txt 78 | 79 | 同一个文件合并时的冲突都合并到了文件中,git不辅助做修改,需要自行修改,修改文件后重新commit 80 | 81 | ``` txt 82 | This is the first in the read.txt 83 | <<<<<<< HEAD 84 | In the develop branch 85 | ======= 86 | in the feature branch 87 | >>>>>>> feature 88 | ``` 89 | 90 | ### 方案1 91 | 92 | 修改后,假设此处2句都要可以改成 93 | 94 | ```txt 95 | This is the first in the read.txt 96 | In the develop branch 97 | in the feature branch 98 | ``` 99 | 100 | git commit 101 | 102 | ### 方案2 103 | 104 | 修改后,假设此处可以改成 master 105 | 106 | ``` txt 107 | This is the first in the read.txt 108 | In the dmaster branch 109 | ``` 110 | 111 | git commit 112 | 113 | 114 | 115 | ## 操作方案2--不同分支处理了不同文件,各分支间的修改相互独立没有修改到同一个文件 116 | 117 | 正常合并 (merge) 不会报出 冲突异常(conflict)。 118 | 119 | 120 | 121 | ## 操作方案3--不同分支修改了同一 文件的文件名 122 | 123 | 合并时报出 冲突异常 124 | 125 | 比如 read.txt 在分支 develop 改成 read1.txt 126 | 127 | 而另外一个人 操作 分支feature 时 将read.txt 改成了 read2.txt 128 | 129 | 130 | 131 | 这时 master 合并2个分支时 会出现异常,结果导致出现 read1.txt 与read2.txt 需要合理甄别,或者讨论后决定是 留住哪一个文件,还是都留下来,在 add 以及commit -------------------------------------------------------------------------------- /chapter03/3.Git分支图示.md: -------------------------------------------------------------------------------- 1 | ## Git图示 2 | 3 | ![](./gitpic2.jpg) -------------------------------------------------------------------------------- /chapter03/gitpic2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leobod/GitGuide/702c3cdbbf394f20f68fd5062d599b08bb403d73/chapter03/gitpic2.jpg -------------------------------------------------------------------------------- /chapter04/1.Git 远程分支管理.md: -------------------------------------------------------------------------------- 1 | # Git 远程分支管理 2 | 3 | ## 单词 4 | 5 | + remote 6 | + clone 7 | 8 | ## 语法 9 | 10 | ### git remote 操作 11 | 12 | ```git 13 | git remote -v //查看远程信息 14 | git remote add //添加 远程 同时可以指定 branch 以及其他 15 | git remote rename //修改 远程 名称 16 | git remote remove //删除 远程 引用 17 | …………………… 18 | ``` 19 | 20 | ### git clone 操作 21 | 22 | ```git 23 | git clone [url/path] 24 | //从指定的 URL或路径 克隆仓库到本地 25 | git clone --bare file:///path/……/project_name name.git 26 | //将指定工程的版本库 克隆或者备份到 当前位置,不加--bare原样克隆 27 | ``` 28 | 29 | 30 | 31 | ## 语义 32 | 33 | ### 不同克隆方法 34 | 35 | ```git 36 | git clone /path/…………/project.git //哑协议 克隆 37 | git clone file:///path/…………/project //智能协议 克隆 38 | git clone http://github.com/name/progit.git //http协议 克隆 39 | git clone git@github.com:leobod/GitGuide.git //SSH协议 克隆 40 | ``` 41 | 42 | ### 克隆一个 github项目 43 | 44 | ```git 45 | git clone https://github.com/leobod/GitGuide.git //克隆当前项目到本地 46 | git remote -v 47 | shell显示 48 | origin git@github.com:leobod/GitGuide.git (fetch) 49 | origin git@github.com:leobod/GitGuide.git (push) 50 | 克隆的项目 远程名一般为 origin 远端分支一般叫 origin/master 或者其他 51 | ``` 52 | 53 | ### 使用远程自己 连接github项目 54 | 55 | ```git 56 | git remote add github https://github.com/leobod/GitGuide.git 57 | git remote -v 58 | shell显示 59 | github git@github.com:leobod/GitGuide.git (fetch) 60 | github git@github.com:leobod/GitGuide.git (push) 61 | 请类比上文 62 | ``` 63 | 64 | 65 | 66 | ### 使用远端一般 需要提前配置好 SSH 密钥 并将公钥 放置于GitHub 中使得GitHub放行 67 | 68 | 69 | 70 | > 更对内容请参考 GIt 官网 [3.5 Git 分支 - 远程分支](https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E8%BF%9C%E7%A8%8B%E5%88%86%E6%94%AF) 71 | 72 | -------------------------------------------------------------------------------- /chapter04/2.Git 本地与远程同步操作.md: -------------------------------------------------------------------------------- 1 | # git 本地远程同步操作 2 | 3 | ## 单词 4 | 5 | + fetch 6 | + pull 7 | + push 8 | 9 | ## 语法 10 | 11 | ```git 12 | git fetch //从指定 远程 拉取文件到版本库 13 | git pull //从指定 远程 拉取并合并到 版本库 14 | git push //将版本库 推送到 远程仓库去 15 | ``` 16 | 17 | 18 | 19 | ## 语义 20 | 21 | ### 在c0分支上做修改,并提交到远端,之后切换到master 合并c0分支的修改,再次提交 22 | 23 | ```git 24 | git clone https://github.com/leobod/GitGuide.git 25 | cd GitGuide/ 26 | git checkout c1 27 | vi README.md 28 | 做一些修改 29 | git add --all 30 | git commit -m 'message' 31 | git push --set-upstream origin c1 32 | 33 | git checkout master 34 | git merge c1 35 | git push --set-upstream origin master 36 | ``` 37 | 38 | ### 当其他人修改了 文件,或者当远端 fast-forword(快过本地时,也就是commit 在上一回基础上有变更而本地 还没获取远端更新时) 39 | 40 | 方案1: 41 | 42 | ```git 43 | git fetch origin 44 | ``` 45 | 46 | 方案2: 47 | 48 | ```git 49 | git pull origin 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /chapter04/3.Git 远程分支关联.md: -------------------------------------------------------------------------------- 1 | # 远程分支与本地分支映射关联 2 | 3 | ## 单词 4 | 5 | + --set-upstream-to 6 | + -u 7 | + --unset-upstream 8 | + -vv //此处是2个v 9 | 10 | 11 | 12 | ## 语法 13 | 14 | ### 添加本地与远程映射 15 | 16 | ```git 17 | git branch --set-upstream-to=origin/remote_branch local_branch 18 | //此处不是必须一一对应 19 | 也可以使用 20 | git branch -u origin/remote_branch local_branch 21 | 22 | 但是一般 我们建立分支是在本地,提交也是在本地 23 | 所以做 push时候 一般已经指定了 如: 24 | git checkout c1 //切换到c1 分支 25 | git push --set-upstream origin c1 //当处于 c1 分支时,这样提交 就是 本地c1与远端c1关联 26 | ``` 27 | 28 | ## 撤销分支关联 29 | 30 | ```git 31 | git branch --unset-upstream local_branch 32 | ``` 33 | 34 | ### 查看所有分支的映射关系 35 | 36 | ```git 37 | git branch -vv //此处是2个v 38 | ``` 39 | 40 | ### 查看所有分支(本地加远端) 41 | 42 | ```git 43 | git branch -av 44 | ``` 45 | 46 | ### 删除远程分支 47 | 48 | ``` 49 | git push origin --delete 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /chapter04/4.Git对版本库的文件取消track.md: -------------------------------------------------------------------------------- 1 | ## Git对版本库的文件取消track 2 | 3 | ### 取消track方法 4 | 5 | ``` 6 | git rm --cached file/dir 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /chapter04/5.Git远程其他操作.md: -------------------------------------------------------------------------------- 1 | ## GIt远程其他操作 2 | 3 | [toc] 4 | 5 | 6 | 7 | ### Git远程仓库 8 | 9 | 此处关注的是remote,而不太侧重clone 10 | 11 | #### 添加远程 12 | 13 | ``` 14 | git remote add //添加 远程 同时可以指定 branch 以及其他 15 | ``` 16 | 17 | #### 查看远程 18 | 19 | ``` 20 | git remote -v 21 | 22 | git remote show 23 | 比如 24 | git remote show origin 25 | ``` 26 | 27 | #### 远程仓库的重命名 28 | 29 | ``` 30 | git remote rename 31 | 比如 32 | git remote rename origin github 33 | git remote rename origin gitee 34 | ``` 35 | 36 | #### 远程仓库的移除 37 | 38 | ``` 39 | git remote remove origin 40 | ``` 41 | 42 | #### pull与push 43 | 44 | ```git 45 | git fetch //从指定 远程 拉取文件到版本库 46 | git pull //从指定 远程 拉取并合并到 版本库 47 | git push //将版本库 推送到 远程仓库去 48 | ``` 49 | 50 | ### 分支手动关联 51 | 52 | ``` 53 | git branch --set-upstream-to=origin/remote_branch local_branch 54 | 55 | git push --set-upstream origin 56 | ``` 57 | 58 | -------------------------------------------------------------------------------- /pdf_release/【官方】Git中文文档.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leobod/GitGuide/702c3cdbbf394f20f68fd5062d599b08bb403d73/pdf_release/【官方】Git中文文档.pdf -------------------------------------------------------------------------------- /pdf_release/【第一版】Git笔记.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leobod/GitGuide/702c3cdbbf394f20f68fd5062d599b08bb403d73/pdf_release/【第一版】Git笔记.pdf --------------------------------------------------------------------------------