Git开发流程学习笔记

基础设置

远程仓库里需要记录提交记录是由谁来完成的,所以我们需要给本地的git设置用户名和邮箱:

git config --global user.name "Xiong"
git config --global user.email "1624325694@qq.com"

配置的用户名和邮箱对push代码到远程仓库时的身份验证没有作用,他们仅仅会出现在远程仓库的commits里。

分支规范说明

命名规范创建自合并到说明
master长期存在,产品发布分支,管理员合并新版本或hotfix
pre-productionmastermaster长期存在。产品预发布分支,基于master,用于修复产品紧急bug以及验证。定期merge到master分支。开发 可进行hotfix修复。
developmaster长期存在。开发分支,最新的代码分支。开发自行提交。
feature/*developdevelop新功能分支,开发完成,单体测试完成,合并后删除。开发自行创建并销毁。
release/*developdevelop和pre-production新版本发布测试分支,完成测试合并后删除。管理员或测试创建并销毁。
hotfix/*re-productiondevelop和pre-production生产环境中发现的紧急bug的修复。开发创建并销毁。

开发流程

对于开发过程中的不同任务,需要在对应的分支上进行工作并正确地进行合并。每个任务开始前需要按
照指定的步骤完成分支的创建。例如当需要开发一个新的功能时,基本的流程如下:

  1. 从 develop 分支创建一个新的 feature 分支,如 feature/xyz。
  2. 在该 feature 分支上进行开发,提交代码,push 到远端仓库。
  3. 当代码完成之后,合并到 develop 分支并删除当前 feature 分支。

远程仓库拉取

下面这个仓库是我自己的,你们是没有权限的,请用自己的仓库练习。

# 拉取主分支
git clone https://gitee.com/L-v-l/learn.git
# 拉取指定分支
git clone -b 分支名 https://gitee.com/L-v-l/learn.git
# 也可以在后面指定拉取到特定文件夹
git clone -b 分支名 https://gitee.com/L-v-l/learn.git learn-branch

# 拉取过后需要进入到项目目录中
cd learn

分支操作

查看分支

# 查看本地分支
git branch
# 查看本地和远程分支
git branch -a

切换指定分支

git checkout 分支名

创建分支

创建本地分支

git branch 分支名

基于某个远程分支创建分支并切换分支

git checkout -b develop origin/master

推送本地分支并创建远程分支

git push origin develop

删除远程分支

git push origin --delete 远程分支名

使用gitflow完成新分支的创建和代码的提交

初始化

本地需要有master分支和develop分支, 没有就使用下面两条命令进行创建分支

git checkout -b master origin/master
git checkout -b develop origin/develop

使用初始化命令

git flow init

如果填错,可以重新再来一遍

git flow init -f

命令执行示例

$ git flow init
Which branch should be used for bringing forth production releases?
   - develop
   - master
Branch name for production releases: [master]
Which branch should be used for integration of the "next release"?
   - develop
Branch name for "next release" development: [develop]
How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
Hooks and filters directory? [C:/Users/Xiong/Desktop/code/learn/.git/hooks]

创建一个新的分支

此命令会以刚才选的的develop分支为基础创建一个新的分支

git flow feature start 分支名

命令执行示例:

$ git flow feature start test
Switched to a new branch 'feature/test'
Summary of actions:
- A new branch 'feature/test' was created, based on 'develop'
- You are now on branch 'feature/test'
Now, start committing on your feature. When done, use:
     git flow feature finish test

将创建的分支推送到远程分支

git flow feature publish 分支名

命令执行示例:

$ git flow feature publish test
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.2]
remote: Create a pull request for 'feature/test' on Gitee by visiting:
remote:     https://gitee.com/L-v-l/learn/pull/new/L-v-l:feature/test...L-v-l:master
To https://gitee.com/L-v-l/learn.git
 * [new branch]      feature/test -> feature/test
Branch 'feature/test' set up to track remote branch 'feature/test' from 'origin'.
Already on 'feature/test'
Your branch is up to date with 'origin/feature/test'.

Summary of actions:
- The remote branch 'feature/test' was created or updated
- The local branch 'feature/test' was configured to track the remote branch
- You are now on branch 'feature/test'

删除分支

git flow feature finish 分支名

命令执行示例:

$ git flow feature finish test
Switched to branch 'develop'
Your branch is up to date with 'origin/master'.
Already up to date.
remote: Powered by GITEE.COM [GNK-6.2]
To https://gitee.com/L-v-l/learn.git
 - [deleted]         feature/test
Deleted branch feature/test (was 87102c7).

Summary of actions:
- The feature branch 'feature/test' was merged into 'develop'
- Feature branch 'feature/test' has been locally deleted; it has been remotely deleted from 'origin'
- You are now on branch 'develop'

合并分支

现在我开发的模块B已经完成,并提交到了远程分支

Xiong@DESKTOP-BAMPTMD MINGW64 ~/Desktop/code/learn (feature/test)
$ git add .

Xiong@DESKTOP-BAMPTMD MINGW64 ~/Desktop/code/learn (feature/test)
$ git commit -m "添加模块B"
[feature/test 898bcd7] 添加模块B
 1 file changed, 1 insertion(+)
 create mode 100644 module/B/1.txt

Xiong@DESKTOP-BAMPTMD MINGW64 ~/Desktop/code/learn (feature/test)
$ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 453 bytes | 453.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.2]
To https://gitee.com/L-v-l/learn.git
   87102c7..898bcd7  feature/test -> feature/test

将本分支合并到develop分支

切换到develop分支,并拉取最新代码

Xiong@DESKTOP-BAMPTMD MINGW64 ~/Desktop/code/learn (feature/test)
$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/master'.

Xiong@DESKTOP-BAMPTMD MINGW64 ~/Desktop/code/learn (develop)
$ git pull
Already up to date.

合并分支feature/test分支到develop分支

Xiong@DESKTOP-BAMPTMD MINGW64 ~/Desktop/code/learn (develop)
$ git merge feature/test
Updating 87102c7..898bcd7
Fast-forward
 module/B/1.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 module/B/1.txt

将代码推送到远程develop分支

$ git push origin develop
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.2]
To https://gitee.com/L-v-l/learn.git
   87102c7..898bcd7  develop -> develop
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值