GIT WORKFLOW

this readme created on 2019.07.28
by Suarez7988

这是一遍介绍git版本控制流程的中文说明,必须通篇阅读一下

https://github.com/oldratlee/translations/tree/master/git-workflows-and-tutorials

此教程参考公司gitlab仓库写作,从注册、拉取远程仓库、到提交与冲突解决

使用的是“功能分支工作流”模式,详见子章节

https://github.com/oldratlee/translations/blob/master/git-workflows-and-tutorials/workflow-feature-branch.md

1. edit gitconfig like the example as follows:

the git config file is: ~/.gitconfig

[user]
name = suarez
email = suarez7988@XXX.cn
[alias]
log = log --color
st = status
co = checkout
br = branch
up = rebase
ci = commit
dw = diff --color-words
[color]
ui = true
diff = auto
[core]
editor = vim

2. config ssh key

login https://gitlab.xxx.com/

add your ssh key in https://gitlab.xxx..com/profile/keys

you can add many keys in different development environment by yourself

3. copy data repository to local

git clone git@GIT_URL:THIS_PROJECT YOUR_DIRECTORY

if you get "Permission denied (publickey)" problem, See 8.g.

4. create or switch to your own branch

if the project is just created, your should goto 8.i.

cd YOUR_DIRECTORY
git checkout -b YOUR_BRANCH_NAME master

if your branch exists, you can also:

git checkout YOUR_BRANCH_NAME

5. do the work on your own branch

git checkout YOUR_BRANCH_NAME
git status
git add <changed files>
git commit -m "changes reasons"

6. publish your code review(CR)

git checkout master  # 将本地代码切换到本地的master分支
git pull origin master master # 将origin/master分支的改动更新到本地的master分支
git checkout YOUR_BRANCH_NAME # 将本地代码切换到本地的YOUR_BRANCH_NAME分支
git pull origin master YOUR_BRANCH_NAME # 将origin/master的改动更新到本地的YOUR_BRANCH_NAME分支,这步可能会报冲突Conflicts字样,如果冲突,请先解决冲突,然后再继续下面流程,解决冲突的办法见下面8.e
git push -u origin YOUR_BRANCH_NAME # 将本地YOUR_BRANCH_NAME的改动推送到远端origin/YOUR_BRANCH_NAME
git diff master YOUR_BRANCH_NAME > patch[_main change reason].txt # 比较本地YOUR_BRANCH_NAME分支和master分支的不同

if your level is developer, you should create Merge Request on the webpage

  • go to the project webpage
  • if it shows a 'create Merge Request' button click it

    (or choose 'Merge Requests' click button 'New Merge Requests' select project and YOUR_BRANCH_NAME for 'Source branch'

    select the same project and master for 'Target branch' click 'Compare branches and continue')
  • write main change reason for 'Title'
  • select reviewer for 'Assignee'
  • click 'Submit merge request'

the viewer will receive a mail for this merge request.

after he/she review the code, if he/she 'Close merge request', you should goto step 5 and correct your code; if he/she 'Accept merge request', NOTE your branch will merge to master directly.

if your level is master or higher, you can also do the following directly:

git checkout master
git pull
git pull origin YOUR_BRANCH_NAME
git push origin master

7. tag for code publish(only for SA)

git tag -f yyyymmddhh_tag
git push --tags

8. addtional operations

8.a. see all the branch including remote and local

git branch -a

8.b. delete useless branch

delete local branch
git branch -d YOUR_BRANCH_NAME
delete remote branch
git push origin :YOUR_BRANCH_NAME

8.c. you know

git blame <file>

8.d. only add all tracked file

git add -u

8.e. resolve a conflict

use "git status" to see where the problem is

冲突是常见的,不代表你的提交是错误的,当你和另外一个同事同时修改了同一个文件,并且他先于你把这份文件提交到origin/master分支上时,你在git pull origin master YOUR_BRANCH_NAME时才可能冲突,冲突发生时terminal里会显示如下字样:

Auto-merging xxx.py
CONFLICT (content): Merge conflict in xxx.py
Automatic merge failed; fix conflicts and then commit the result.
if there is still problem exsits, do the following operation:
冲突发生后,切忌慌张,切忌逃避,切忌埋怨同事,解决办法也很简单
主要方式就是先编辑冲突的文件,然后git commit提交。
冲突的文件中,<<<<<<与=====中的代码为服务器改动的代码,=====与>>>>>>中的代码为本地改动的代码,
手动编辑冲突的部分,理解同事的修改逻辑,需要你将同事的改动精髓和你的改动相融合,
如果你是第一次处理冲突,请自行上百度搜索git冲突解决方案,来一次愉快的学习。
严禁没解决冲突就直接发merge request!

8.f. merge newest code to local branch

if you just want your local branch merge newest code

git pull origin master

but if you want to update your local master and local branch at the same time, goto 6

8.g. solve "Permission denied (publickey)" problem

first, check your key is add to the profile of your gitlab

then do following command to see if your key located correctly

ssh -vT git@GIT_URL

in most cases, change the key file name to ~/.ssh/id_rsa will solve the problem

but if you have more than one key, you can do the following suggestion

edit the file ~/.ssh/config

Host "GIT_URL"
HostName "GIT_URL"
User "git"
IdentityFile "~/.ssh/YOUR_KEY_FILE"

if the result of "ssh GIT_URL" is:

PTY allocation request failed on channel 0
Welcome to GitLab, hongjun.liu!
Connection to gitlab.xxx.com closed.

thank GOD, you finally succeed

then you can clone the remote repository use following command:

git clone git@GIT_URL:THIS_PROJECT YOUR_DIRECTORY

for more information you can goto https://help.github.com/articles/error-permission-denied-publickey

8.h. revert local commit

if you get "Your branch is ahead of 'origin/master' by n commit", but you do not want to push these changes

git reset --hard HEAD~n

8.i. start a new project

git clone git@GIT_URL:hongjun.liu/PROJECT_NAME.git
cd PROJECT_NAME
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

NOTE that, the very first commit should push at the first time, this step create a remote branch called 'master'.

开发工具之GIT的更多相关文章

  1. IDEA开发工具使用 git 创建项目、拉取分支、合并分支

    转载自:https://blog.csdn.net/qq_39470733/article/details/80366435 工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有 ...

  2. 开发工具之Git(二)

    目录 四.Git安装与配置 (一)安装 (二)配置 (三)创建仓库 五.Git基本命令 六.Git分支 上一篇讲了Git的基本原理,建议没看过的同学先看看,然后这次我们来讲Git的具体操作和指令. 四 ...

  3. 开发工具之Git(一)

    目录 一.什么是Git 二.Git基本原理 三.Git用户交互 一.什么是Git 答:Git是一个分布式版本控制软件.另外提一句,它的开发者就是大名鼎鼎的Linux之父Linus. 版本控制,顾名思义 ...

  4. Java,面试题,简历,Linux,大数据,常用开发工具类,API文档,电子书,各种思维导图资源,百度网盘资源,BBS论坛系统 ERP管理系统 OA办公自动化管理系统 车辆管理系统 各种后台管理系统

    Java,面试题,简历,Linux,大数据,常用开发工具类,API文档,电子书,各种思维导图资源,百度网盘资源BBS论坛系统 ERP管理系统 OA办公自动化管理系统 车辆管理系统 家庭理财系统 各种后 ...

  5. 如何使用IDEA开发工具中右键中的Git图形化工具

    首先,你的项目一定是git服务器上面down下来的,下面来演示如何使用IntelliJ IDEA 开发中在鼠标右键中提供的一个非常方便的图形化Git管理工具: 这里使用的IDEA开发工具的版本是 In ...

  6. 开发工具--浅谈Git

    工具|浅谈Git Git这个工具,是我一直想写文章,终于我实现了我的想法.在我开始写之前,发表一下自己的看法,git只是一个工具,既然已经认定是一个工具,那么一定具备工具这类的共同特征,请用面向对象的 ...

  7. Chrome 开发工具之Console

    前段时间看git的相关,记的笔记也大致写到了博客上,还有些因为运用不熟,或者还有一些疑惑点,暂时也不做过多纠缠,之后在实践中多运用得出结论再整理分享吧. 工欲善其事,必先利其器.要想做好前端的工作,也 ...

  8. Android 常用开发工具以及Mac常用软件

    Android 常用的开发工具记录.其中包括AndroidStudio(IDEA)插件.Mac 上好用的软件以及国内知名Android开发者博客等. Android Studio 插件 codota ...

  9. 超全的web开发工具和资源

    首页 新闻 产品 地图 动态 城市 帮助 论坛 关于 登录 注册 · 不忘初心,继续前进,环境云V2接口正式上线 · 环境云测点地图全新改版 · 祝福各位环境云用户中秋快乐!   平台信息 培训互动 ...

随机推荐

  1. 第九章 利用CSS3制作网页动画

    一.CSS3变形transform 1.平移:translate(x,y) translateX(x) translateY(y) 注意:如果想只向X轴平移那么可以translateX,如果想只向X轴 ...

  2. 【leetcode】1240. Tiling a Rectangle with the Fewest Squares

    题目如下: Given a rectangle of size n x m, find the minimum number of integer-sided squares that tile th ...

  3. 用pyinstaller打包python程序、打包pyqt程序

    将.py脚本拷贝到一个文件夹中: 然后shift+右键,打开Powershell窗口: -F:设置打包为一个.exe文件.(缺点打开速度慢,不加-F则不打包为一个.exe,优点简洁方便) -w:设置不 ...

  4. sql server 游标的知识

    一:认识游标   游标是SQL Server的一种数据访问机制,它允许用户访问单独的数据行.用户可以对每一行进行单独的处理,从而降低系统开销和潜在的阻隔情况,用户也可以使用这些数据生成的SQL代码并立 ...

  5. Bluetooth M590 mouse problem Ubuntu

    I restart it in the terminal, and it works: Code: $ sudo -i # bluetoothctl [bluetooth]# power off [b ...

  6. AtomicInteger如何保证线程安全以及乐观锁/悲观锁的概念

    众所周知,JDK提供了AtomicInteger保证对数字的操作是线程安全的,线程安全我首先想到了synchronized和Lock,但是这种方式又有一个名字,叫做互斥锁,一次只能有一个持有锁的线程进 ...

  7. CF811E Vladik and Entertaining Flags

    嘟嘟嘟 看题目这个架势,就知道要线段树,又看到维护联通块,那就得并查集. 所以,线段树维护并查集. 然而如果没想明白具体怎么写,就会gg的很惨-- 首先都容易想到维护区间联通块个数和区间端点两列的点, ...

  8. MySQL服务器基准测试

    一.基准测试简介 1.什么是基准测试 数据库的基准测试是对数据库的性能指标进行定量的.可复现的.可对比的测试. 基准测试与压力测试 基准测试可以理解为针对系统的一种压力测试.但基准测试不关心业务逻辑, ...

  9. MySQL数据分析-(12)表操作补充:字段属性

    大家好,我是jacky朱元禄,很高兴继续跟大家学习MySQL数据分析实战,今天我们分享的主题是表操作补充之字段属性,依照惯例第一部分,jacky先跟大家分享本课时的学习逻辑 (一)学习逻辑 我们说创建 ...

  10. MongoDB-查询关键字/排序等

    查询关键字 并列查询$and # 条件都成立才可以查询到结果 db.stutent.find({$and:[{name:"小漩涡"},{age:30}]}) 或查询$or # 有一 ...