├── src └── app.js ├── LICENSE ├── .gitignore └── README.md /src/app.js: -------------------------------------------------------------------------------- 1 | console.log("1.0 开发完毕") 2 | console.log("1.0 bug修复了") 3 | console.log("1.0 bug真的修复完毕了") 4 | 5 | console.log("2.0 开发完毕了") 6 | console.log("2.0 bug已经修复了") -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 段子黄 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # git_branch_test 2 | 3 | Git基本操作及Git分支演练 4 | 5 | ## Git的基本操作 6 | 7 | ```javascript 8 | 1、从远程仓库克隆到本地 9 | git clone 远程仓库地址 10 | 11 | 2、更改本地代码之后提交相关操作 12 | git status 查看本地仓库的状态 13 | 14 | git add . 把更改的添加到暂存区 15 | 16 | git commit -m "注释" 提交到本地仓库 17 | 18 | 3、回滚 19 | git reset --hard HEAD 回滚最近的一个版本 20 | 21 | git reset --hard 版本号 回滚到指定的版本 22 | 23 | 4、把本地的代码推送到服务器 24 | git push origin master -u xxx 25 | 26 | 5、将本地仓库和远程仓库建立关联关系 27 | git remote add origin git@gitee.com:manageritcast/pyg_middleware_27.git 28 | 29 | 6、推送到远程,并且建立跟踪分支 30 | git push -u origin master 31 | ``` 32 | 33 | ## git本地仓库添加到远程仓库 34 | 35 | > 前提:在本地通过 git init 创建好了本地仓库,在远程也建立了远程仓库 36 | 37 | ``` 38 | 1、切换到要上传的项目的根目录【下面有.git文件】 39 | 40 | 2、将远程仓库与本地仓库关联 41 | git remote add origin git@github.com:Duanzihuang/react_redux_cart.git 42 | 43 | 3、将项目添加到本地仓库 44 | git add . 45 | 46 | 4、提交到本地仓库 47 | git commit -m "1-完成了受控组件Checkbox案例" 48 | 49 | 5、第一次推送【记得加上-u】 50 | # 由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。 51 | git push -u origin master 52 | 53 | 6、如果发生错误 说明 本地仓库和远程仓库的文件有冲突,你先pull远端的版本,解决了冲突才能push 54 | git pull origin master / git pull origin master --allow-unrelated-histories 55 | git push -u origin master 56 | 57 | 7、建议在Github等网站新建仓库的时候,不要勾选README和.gitignore选项,统一由本地生成,这样在建立关联关系的时候就不会有冲突了 58 | ``` 59 | 60 | ## 有关分支 61 | 62 | 1. 当我们创建一个远程仓库的时候,就会默认有一个主分支【创建仓库就会自带的】 63 | 2. 我们把远程仓库,克隆到本地之后,本地也有一个master分支【通过git branch查看】 64 | 3. 主分支【master】主要用于我们主线代码的开发 65 | 4. 新建分支的目的是为了,保证我们主分支继续执行的情况下,做一些其它的事情【比如bug修复或是难题攻克】 66 | 67 | 68 | ## Git分支操作 69 | ```javascript 70 | 1、查看本地有哪些分支 71 | git branch 72 | 73 | 2、切出一个新分支 74 | git checkout -b v1.0_bugfix_branch 75 | 76 | 3、把新分支推动远程仓库,做一个备份 77 | git push origin v1.0_bugfix_branch 78 | 79 | 4、切回主分支,并且把 v1.0_bugfix_branch 已经修复的代码合并会主分支 80 | git checkout master 81 | git merge v1.0_bugfix_branch 82 | 83 | 做完这一步,本地的master已经拥有修改之后的代码 84 | 85 | 5、把本地的master的代码推送远程仓库的master 86 | git push origin master 87 | ``` 88 | 89 | ##Git分支的其它指令 90 | 91 | ``` 92 | 1、查看远程仓库信息 93 | git remote 94 | 95 | 2、查看远程仓库的版本及地址 96 | git remote -v 97 | 98 | 3、查看远程仓库的基本信息 99 | git remote show origin 100 | 101 | 4、查看本地分支 102 | git branch 103 | 104 | 5、查看所有分支【包含远程分支】 105 | git branch -a 106 | ``` 107 | 108 | ## Git冲突处理 109 | 110 | 1. 多人在同一时间操作同一个文件的时候有冲突 111 | 2. 如果多个人要更改同一文件,最好的方式是分时间处理,比如某一个人先提交,然后另外一个人pull下来再改 112 | 3. 万一真的出现了冲突,我们先要把自己的代码备份,回退到某一个没有冲突的版本,再把代码拷贝上去,最后在由一个人去提交 --------------------------------------------------------------------------------