学习Git(四)
-
1、GIT基础
GIT是一个分布式版本管理系统,速度快,适合大规模,跨地区多人协同开。SVN是一个集中式版本管理系统。
(1)GIT生态
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。GIT分布式版本管理系统
Gitlab git私库解决方案
Github git公有库解决方案
(2)Git安装
Centos:
yum install -y git
Ubuntu:
apt-get install git
Windows安装git bash
Linux编译安装
注意不要使用git 1.8以下版本,推荐使用2.7版本
①编译安装git
[root@linux-node1 ~]# yum install -y epel-release 安装依赖包: [root@linux-node1 ~]# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker [root@linux-node1 ~]# wget https://github.com/git/git/archive/v2.7.4.zip [root@linux-node1 ~]# yum install -y unzip [root@linux-node1 ~]# unzip git-v2.7.4.zip [root@linux-node1 ~]# cd git-2.7.4 [root@linux-node1 git-2.7.4]# make prefix=/usr/local/git all [root@linux-node1 git-2.7.4]# make prefix=/usr/local/git install [root@linux-node1 git-2.7.4]# rm -rf /usr/bin/git [root@linux-node1 git-2.7.4]# ln -s /usr/local/git/bin/git /usr/bin/git [root@linux-node1 git-2.7.4]# git --version git version 2.7.4 ②初始化仓库 [root@linux-node1 ~]# mkdir test [root@linux-node1 ~]# cd test [root@linux-node1 test]# git init #将test目录初始化仓库 [root@linux-node1 test]# git config --global user.name"*****" [root@linux-node1 test]# git config --global user.email *******@qq.com 四个区域: 远程仓库<-->本地仓库<-->暂存区域<-->工作目录 四种状态 Untracked、Unmodified、Modified、Staged Untracked(工作目录)-->git add -->Staged(暂存区)-->git commit版本-->Unmodified(本地仓库)-->Edit file-->Modified-->Stage the file-->Staged ③常用命令: git add 加入暂存 git status 查看状态 git status -s 状态概览 git diff 尚未暂存的文件 git diff --staged 暂存区文件 git commit 提交更新 git reset 回滚 git rm 从版本库中移除 git rm --cached README 从暂存区中移除 git mv 相当于mv git rm git add 三个命令 使用演示: [root@linux-node1 test]# touch index.html ==>创建文件 [root@linux-node1 test]# vim index.html [root@linux-node1 test]# git status ==>此时文件处于工作目录中 位于分支 master 初始提交 未跟踪的文件: (使用 "git add <文件>..." 以包含要提交的内容) index.html 提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪) [root@linux-node1 test]# git add index.html ==>加入代码库 [root@linux-node1 test]# git status ==>此时文件处于暂存区 位于分支 master 初始提交 要提交的变更: (使用 "git rm --cached <文件>..." 以取消暂存) 新文件: index.html [root@linux-node1 test]# git commit -m "first commit" ==>提交到本地仓库 [master(根提交) c6bc04f] first commit 1 file changed, 3 insertions(+) create mode 100644 index.html [root@linux-node1 test]# git status 位于分支 master 无文件要提交,干净的工作区 [root@linux-node1 test]# git log commit c6bc04f90d4ef442e2c4d5bc788b21de239332da ==>回滚需要的id Author: ****** <******@qq.com> Date: Fri Dec 8 22:37:40 2017 +0800 first commit [root@linux-node1 test]# touch pay.html [root@linux-node1 test]# vim pay.html [root@linux-node1 test]# git add pay.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html [root@linux-node1 test]# touch news.html [root@linux-node1 test]# echo "123" > news.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html Untracked files: (use "git add <file>..." to include in what will be committed) news.html [root@linux-node1 test]# git add news.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: news.html new file: pay.html [root@linux-node1 test]# git rm --cached pay.html #将pay.html从暂存区移除 rm 'pay.html' [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: news.html Untracked files: (use "git add <file>..." to include in what will be committed) pay.html [root@linux-node1 test]# git commit -m "news" [master d83603a] news 1 file changed, 1 insertion(+) create mode 100644 news.html [root@linux-node1 test]# git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) pay.html nothing added to commit but untracked files present (use "git add" to track) [root@linux-node1 test]# git log commit d83603a56b8926630d31b46898e4b6d69293d946 Author:******** Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ***************** Date: Fri Dec 8 22:37:40 2017 +0800 first commit [root@linux-node1 test]# echo "66666" >> pay.html [root@linux-node1 test]# git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) pay.html nothing added to commit but untracked files present (use "git add" to track) [root@linux-node1 test]# git add pay.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html [root@linux-node1 test]# git commit -m "pay modelue" [master e55a302] pay modelue 1 file changed, 2 insertions(+) create mode 100644 pay.html [root@linux-node1 test]# git status On branch master nothing to commit, working directory clean [root@linux-node1 test]# git log commit e55a302e11d967fd25eac1cce8b6c7bed732019b Author:****************** Date: Fri Dec 8 22:49:57 2017 +0800 pay modelue commit d83603a56b8926630d31b46898e4b6d69293d946 Author: ****************** Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ****************** Date: Fri Dec 8 22:37:40 2017 +0800 first commit
-
2、分支管理
[root@linux-node1 test]# git status On branch master nothing to commit, working directory clean 建分支,开发新功能是不能在master分支上开发 [root@linux-node1 test]# git branch about #创建分支 [root@linux-node1 test]# git status On branch master nothing to commit, working directory clean [root@linux-node1 test]# git checkout about #切换分支 Switched to branch 'about' [root@linux-node1 test]# git status On branch about nothing to commit, working directory clean [root@linux-node1 test]# git log #创建的分支是在master分支当前的状态进行创建的。所以在about分支上也会有master的记录 commit e55a302e11d967fd25eac1cce8b6c7bed732019b Author: ************ Date: Fri Dec 8 22:49:57 2017 +0800 pay modelue commit d83603a56b8926630d31b46898e4b6d69293d946 Author: ************ Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ************ Date: Fri Dec 8 22:37:40 2017 +0800 first commit [root@linux-node1 test]# git branch * about master [root@linux-node1 test]# touch about.html [root@linux-node1 test]# echo "about us" >> about.html [root@linux-node1 test]# git add . [root@linux-node1 test]# git commit -m "about" [about 08b200a] about 1 file changed, 1 insertion(+) create mode 100644 about.html [root@linux-node1 test]# git log [root@linux-node1 test]# git checkout master #切换到master分支 Switched to branch 'master' [root@linux-node1 test]# git log [root@linux-node1 test]# git checkout about #切换到about分支 [root@linux-node1 test]# echo "about2" > about2.html [root@linux-node1 test]# git add . [root@linux-node1 test]# git commit -m "about2" [root@linux-node1 test]# git log [root@linux-node1 test]# git checkout master [root@linux-node1 test]# git log [root@linux-node1 test]# git merged about #在master分支上合并about分支 [root@linux-node1 test]# git log [root@linux-node1 test]# git branch test #创建test分支 [root@linux-node1 test]# git checkout test [root@linux-node1 test]# touch "test" > test.html [root@linux-node1 test]# git add . [root@linux-node1 test]# git commit -m "test" [root@linux-node1 test]# git checkout master [root@linux-node1 test]# git branch --merged #查看已经合并的分支 [root@linux-node1 test]# git branch --no-merged #查看未合并的分支 分支命令 git branch例出分支 git branch -v git branch --merged查看哪些分支被合并 git branch --no-merged查看哪些分支未被合并 git branch -d testling删除分支 git checkout切换分支 git merged融合分支
###################################################################
-
1、安装依赖及gitlab
[root@linux-node1 ~]# yum install -y curl policycoreutils openssh-server openssh-clients postfix [root@linux-node1 ~]# systemctl start postfix
-
2、安装gitlab
由于国内网络偏慢,这里使用清华大学的镜像源进行安装gitlab-ce [root@linux-node1 ~]# cat /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 repo_gpgcheck=0 gpgcheck=0 enabled=1 gpgkey= [root@linux-node1 ~]# yum makecache [root@linux-node1 ~]# yum install -y gitlab-ce
-
3、修改配置文件
[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb external_url 'http://192.168.56.11' [root@linux-node1 ~]# gitlab-ctl reconfigure 这一步时间比较长,耐心等待 gitlab常用命令: 关闭gitlab:[root@linux-node1 ~]# gitlab-ctl stop 启动gitlab:[root@linux-node1 ~]# gitlab-ctl start 重启gitlab:[root@linux-node1 ~]# gitlab-ctl restart 重载配置文件: gitlab-ctl reconfigure
可以使用gitlab-ctl
管理gitlab,例如查看gitlab状态:
[root@linux-node1 ~]# gitlab-ctl status run: gitaly: (pid 53207) 176s; run: log: (pid 52331) 647s run: gitlab-monitor: (pid 53233) 174s; run: log: (pid 52406) 620s run: gitlab-workhorse: (pid 53189) 180s; run: log: (pid 52274) 671s run: logrotate: (pid 52307) 654s; run: log: (pid 52306) 654s run: nginx: (pid 53694) 2s; run: log: (pid 52285) 665s run: node-exporter: (pid 52388) 631s; run: log: (pid 52387) 631s run: postgres-exporter: (pid 53262) 171s; run: log: (pid 52478) 581s run: postgresql: (pid 52013) 855s; run: log: (pid 52012) 855s run: prometheus: (pid 53245) 172s; run: log: (pid 52443) 598s run: redis: (pid 51951) 867s; run: log: (pid 51950) 867s run: redis-exporter: (pid 52426) 609s; run: log: (pid 52425) 609s run: sidekiq: (pid 52256) 677s; run: log: (pid 52255) 677s run: unicorn: (pid 52218) 683s; run: log: (pid 52217) 683s 提示:gitlab需要使用到80端口,所以得保证80端口不被占用 [root@linux-node1 ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 963 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 1156 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 1392 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 1544 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 22057 root 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 22793 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 23247 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 23367 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 26356 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 64149 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 64641 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) [root@linux-node1 ~]# systemctl stop httpd [root@linux-node1 ~]# gitlab-ctl restart ok: run: gitaly: (pid 55012) 0s ok: run: gitlab-monitor: (pid 55022) 1s ok: run: gitlab-workhorse: (pid 55025) 0s ok: run: logrotate: (pid 55034) 1s ok: run: nginx: (pid 55036) 0s ok: run: node-exporter: (pid 55046) 1s ok: run: postgres-exporter: (pid 55051) 0s ok: run: postgresql: (pid 55059) 1s ok: run: prometheus: (pid 55066) 0s ok: run: redis: (pid 55072) 0s ok: run: redis-exporter: (pid 55081) 0s ok: run: sidekiq: (pid 55105) 0s ok: run: unicorn: (pid 55112) 0s [root@linux-node1 ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 54794 root 8u IPv4 1562548 0t0 TCP *:http (LISTEN) nginx 54802 gitlab-www 8u IPv4 1562548 0t0 TCP *:http (LISTEN)
-
4、浏览器访问登录:
安装完成!
#########################################################################
-
1.创建Group,User,Project
创建一个组,组名为java
Group path http://192.168.56.11/java Visibility Level: #为权限级别,一般使用Private Private Internal Public
创建一个PM的用户作为项目管理者并加入到java组内
创建一个项目:
创建dev1和dev2的用户作为开发者,并加入到项目中
-
2.测试dev1,dev2拉取代码库
(1)生成ssh-key [root@linux-node1 ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Hf3O9F7sS9N04cFUr3Awb/Wec28gTpHYyRZMCzLW9q0 root@linux-node1 The key's randomart image is: +---[RSA 2048]----+ | +..o= .+| | . oo*.Oo.o| | .o.@.++o| | . o.*oo+| | S . o.=+=| | oE= =*| | . ooB| | .+o| | .+| +----[SHA256]-----+ [root@linux-node1 ~]# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLDVIqTAvJtj8Uc+SvhcKOKuDtURt3YBxHo9enUkDjOWtSygLZI4hSrEsnvjHdnxeBGOgjPrxEfMMdNCno4pox7V/8bIU9LRVp2eeQFS+N+bSmbJlTKyODa0tabPwT7URYoiFI3giQamQdA0AwwPCPM/RcXwHJsw4q0O/2woCqNKq2tHaUFBqojd2KvqavzpB+4+AdKJSoabwLhE8dzfjIR/eHY31Y2C/+m9sU504v+R0GsAqr5uifi6Ct9eFvumI54BvHssIpZFZmADTT35b1aP0WSwZb2VEhXjaia8L6h/6ANn1NuHGgYZqNiYT6JILESKbrc7PyJOn9DfHKSMq9 root@linux-node1 (2)将公钥(id_rsa.pub)放进dev1账户中 在admin账户下给dev1,dev2账户设置密码,然后使用dev1登录gitlab,做如下操作添加ssh-key: 测试是否能正常拉取代码库app1 [root@linux-node1 ~]# git clone git@192.168.56.11:java/app1.git Cloning into 'app1'... The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established. ECDSA key fingerprint is SHA256:p2lhKmsPQ6K+dWHHvbJg0GV+Ni9VM7vlViKrYsZLP1s. ECDSA key fingerprint is MD5:22:14:1c:37:de:47:1c:4a:2f:88:b1:dc:e2:d0:02:17. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.56.11' (ECDSA) to the list of known hosts. warning: You appear to have cloned an empty repository. Checking connectivity... done. [root@linux-node1 ~]# ll total 6804 -rw-------. 1 root root 948 Dec 3 01:21 anaconda-ks.cfg drwxr-xr-x 3 root root 17 Dec 20 15:00 app1 drwxr-xr-x 22 root root 24576 Dec 8 22:16 git-2.7.4 drwxr-xr-x 3 root root 65 Dec 9 01:23 test -rw-r--r-- 1 root root 6918037 Dec 8 22:09 v2.7.4.zip [root@linux-node1 ~]# cd app1 [root@linux-node1 app1]# ll total 4 -rw-r--r-- 1 root root 19 Dec 20 15:05 readme
到此,Linux环境下完成了gitlab的授权管理代码库。
下面以PM用户进行创建开发计划
开发一个官网V1.0版本,包含首页和新闻
(1)创建里程碑(Milestone)
(2)依次把任务首页,新闻添加到里程碑,并进行任务分配给开发者
(3)使用dev1用户登录查看,会有任务提示,如图:
(4)dev1开发者收到任务,进行开发
[root@linux-node1 app1]# git checkout -b shouye #创建首页分支 Switched to a new branch 'shouye' [root@linux-node1 app1]# git status On branch shouye nothing to commit, working directory clean [root@linux-node1 app1]# echo "<h1> welcome to www.123.com" > index.html #进行开发 [root@linux-node1 app1]# ll total 8 -rw-r--r-- 1 root root 28 Dec 20 15:50 index.html -rw-r--r-- 1 root root 19 Dec 20 15:05 readme [root@linux-node1 app1]# git add . [root@linux-node1 app1]# git commit -m "shouye" #开发完成,提交本地仓库 [shouye babdcb5] shouye 1 file changed, 1 insertion(+) create mode 100644 index.html [root@linux-node1 app1]# git push origin shouye #提交到远程库 Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: To create a merge request for shouye, visit: remote: http://192.168.56.11/java/app1/merge_requests/new?merge_request%5Bsource_branch%5D=shouye remote: To git@192.168.56.11:java/app1.git * [new branch] shouye -> shouye 可以看到有刚才创建的分支,点击"merge request"合并分支请求,之后PM用户登录处理合并请求。此时,一个功能的开发流程就完成。
总结:
-
PM在gitlab创建任务,分配给开发人员
-
开发人员领取任务后,在本地使用git clone拉取代码库
-
开发人员创建开发分支(git checkout -b dev),并进行开发
-
开发人员完成之后,提交到本地仓库(git commit )
-
开发人员在gitlab界面上申请分支合并请求(Merge request)
-
PM在gitlab上查看提交和代码修改情况,确认无误后,确认将开发人员的分支合并到主分支(master)
-
开发人员在gitlab上Mark done确认开发完成,并关闭issue。这一步在提×××并请求时可以通过描述中填写"close #1"等字样,可以直接关闭issue。
#####################################################################
-
gitlab的备份和恢复
(1)创建备份目录,并授权
[root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-node1 ~]# chown -R git.git /data/ [root@linux-node1 ~]# ll /data/ -d drwxr-xr-x 3 git git 20 Dec 20 16:21 /data/
(2)修改gitlab配置
[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb gitlab_rails['backup_path'] = "/data/backups/gitlab" #备份路径 gitlab_rails['backup_keep_time'] = 604800 #备份7天
[root@linux-node1 ~]# gitlab-ctl reconfigure [root@linux-node1 ~]# gitlab-ctl restart ok: run: gitaly: (pid 41722) 0s ok: run: gitlab-monitor: (pid 41735) 1s ok: run: gitlab-workhorse: (pid 41738) 0s ok: run: logrotate: (pid 41748) 0s ok: run: nginx: (pid 41755) 0s ok: run: node-exporter: (pid 41757) 0s ok: run: postgres-exporter: (pid 41765) 0s ok: run: postgresql: (pid 41792) 0s ok: run: prometheus: (pid 41795) 0s ok: run: redis: (pid 41807) 0s ok: run: redis-exporter: (pid 41812) 1s ok: run: sidekiq: (pid 41822) 0s ok: run: unicorn: (pid 41831) 0s
(3)备份
[root@linux-node1 ~]# gitlab-rake gitlab:backup:create Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] done Dumping repositories ... * java/app1 ... [DONE] * java/app1.wiki ... [SKIPPED] done Dumping uploads ... done Dumping builds ... done Dumping artifacts ... done Dumping pages ... done Dumping lfs objects ... done Dumping container registry images ... [DISABLED] Creating backup archive: 1513759548_2017_12_20_10.2.4_gitlab_backup.tar ... done Uploading backup archive to remote storage ... skipped Deleting tmp directories ... done done done done done done done done Deleting old backups ... done. (0 removed)
(4)查看备份目录
[root@linux-node1 ~]# ll /data/backups/gitlab/ total 72 -rw------- 1 git git 71680 Dec 20 16:45 1513759548_2017_12_20_10.2.4_gitlab_backup.tar #1513759548_2017_12_20_10.2.4为时间戳,备份的时候用的着
(5)恢复备份
删除gitlab中的app1的项目,再恢复 停止数据写入服务: [root@linux-node1 ~]# gitlab-ctl stop unicorn [root@linux-node1 ~]# gitlab-ctl stop sidekiq 恢复数据: [root@linux-node1 ~]# gitlab-rake gitlab:backup:restore BACKUP=1513759548_2017_12_20_10.2.4 [root@linux-node1 ~]# gitlab-ctl restart ok: run: gitaly: (pid 45486) 0s ok: run: gitlab-monitor: (pid 45502) 0s ok: run: gitlab-workhorse: (pid 45507) 1s ok: run: logrotate: (pid 45525) 0s ok: run: nginx: (pid 45531) 1s ok: run: node-exporter: (pid 45536) 0s ok: run: postgres-exporter: (pid 45540) 1s ok: run: postgresql: (pid 45547) 0s ok: run: prometheus: (pid 45555) 1s ok: run: redis: (pid 45562) 0s ok: run: redis-exporter: (pid 45568) 1s ok: run: sidekiq: (pid 45572) 0s ok: run: unicorn: (pid 45614) 0s
此时即可恢复原来的项目
邮件配置: gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['gitlab_email_enabled'] = true gitlab_rails['gitlab_email_from'] = 'xiaoming@126.com' gitlab_rails['gitlab_email_display_name'] = 'gitlab' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.126.com" gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_user_name'] = "xiaoming" gitlab_rails['smtp_password'] = "your password" gitlab_rails['smtp_domain'] = "126.com" gitlab_rails['smtp_authentication'] = "login"
###############################################################################
命令行测试
[root@linux-node1 ~]# mkdir testing [root@linux-node1 ~]# [root@linux-node1 ~]# cd testing/ [root@linux-node1 testing]# [root@linux-node1 testing]# git init Initialized empty Git repository in /root/testing/.git/ [root@linux-node1 testing]# echo "123" > index.html [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "first commit" [master (root-commit) b712131] first commit 1 file changed, 1 insertion(+) create mode 100644 index.html [root@linux-node1 testing]# echo "a file" > a.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "add a.txt" [master 025e8a3] add a.txt 1 file changed, 1 insertion(+) create mode 100644 a.txt [root@linux-node1 testing]# echo "b file" > b.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "add b.txt" [master f4b13b6] add b.txt 1 file changed, 1 insertion(+) create mode 100644 b.txt [root@linux-node1 testing]# git log commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# git checkout -b dev Switched to a new branch 'dev' [root@linux-node1 testing]# git status On branch dev nothing to commit, working directory clean [root@linux-node1 testing]# git log commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# echo "welcome to beijing" > test1.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "test1" [dev d224e8c] test1 1 file changed, 1 insertion(+) create mode 100644 test1.txt [root@linux-node1 testing]# echo "welcome to shanghai" > test2.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "test2" [dev e254dd5] test2 1 file changed, 1 insertion(+) create mode 100644 test2.txt [root@linux-node1 testing]# git log commit e254dd5657d99ed287faf62f74b566a7ac1bf858 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:26:01 2017 +0800 test2 commit d224e8cb4a51a65377c8d8eb75c3613b197e47a4 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:25:37 2017 +0800 test1 commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# git checkout master Switched to branch 'master' [root@linux-node1 testing]# git status On branch master nothing to commit, working directory clean [root@linux-node1 testing]# echo "master1" > master1.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "master1" [master 1ebe653] master1 1 file changed, 1 insertion(+) create mode 100644 master1.txt [root@linux-node1 testing]# echo "master2" > master2.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "master2" [master 814b217] master2 1 file changed, 1 insertion(+) create mode 100644 master2.txt [root@linux-node1 testing]# git log commit 814b217ae84ca4ad541c36d96e9b3c2744bca849 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:28:15 2017 +0800 master2 commit 1ebe65348f73958eeafce158f922d83e386faa78 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:27:50 2017 +0800 master1 commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# git merge dev Merge made by the 'recursive' strategy. test1.txt | 1 + test2.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 test1.txt create mode 100644 test2.txt [root@linux-node1 testing]# git log commit df1da42a6c93152001199d684f01702eb6cb622f Merge: 814b217 e254dd5 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:29:35 2017 +0800 Merge branch 'dev' commit 814b217ae84ca4ad541c36d96e9b3c2744bca849 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:28:15 2017 +0800 master2 commit 1ebe65348f73958eeafce158f922d83e386faa78 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:27:50 2017 +0800 master1 commit e254dd5657d99ed287faf62f74b566a7ac1bf858 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:26:01 2017 +0800 test2 commit d224e8cb4a51a65377c8d8eb75c3613b197e47a4 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:25:37 2017 +0800 test1 commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit
此时,整个分支合并图如下:
分支的状态会保留
如果使用git rebase dev,分支合并图如下:
分支的状态会清除
,
-
1、GIT基础
GIT是一个分布式版本管理系统,速度快,适合大规模,跨地区多人协同开。SVN是一个集中式版本管理系统。
(1)GIT生态
GIT分布式版本管理系统
Gitlab git私库解决方案
Github git公有库解决方案
(2)Git安装
Centos:
yum install -y git
Ubuntu:
apt-get install git
Windows安装git bash
Linux编译安装
注意不要使用git 1.8以下版本,推荐使用2.7版本
①编译安装git
[root@linux-node1 ~]# yum install -y epel-release 安装依赖包: [root@linux-node1 ~]# yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker [root@linux-node1 ~]# wget https://github.com/git/git/archive/v2.7.4.zip [root@linux-node1 ~]# yum install -y unzip [root@linux-node1 ~]# unzip git-v2.7.4.zip [root@linux-node1 ~]# cd git-2.7.4 [root@linux-node1 git-2.7.4]# make prefix=/usr/local/git all [root@linux-node1 git-2.7.4]# make prefix=/usr/local/git install [root@linux-node1 git-2.7.4]# rm -rf /usr/bin/git [root@linux-node1 git-2.7.4]# ln -s /usr/local/git/bin/git /usr/bin/git [root@linux-node1 git-2.7.4]# git --version git version 2.7.4 ②初始化仓库 [root@linux-node1 ~]# mkdir test [root@linux-node1 ~]# cd test [root@linux-node1 test]# git init #将test目录初始化仓库 [root@linux-node1 test]# git config --global user.name"*****" [root@linux-node1 test]# git config --global user.email *******@qq.com 四个区域: 远程仓库<-->本地仓库<-->暂存区域<-->工作目录 四种状态 Untracked、Unmodified、Modified、Staged Untracked(工作目录)-->git add -->Staged(暂存区)-->git commit版本-->Unmodified(本地仓库)-->Edit file-->Modified-->Stage the file-->Staged ③常用命令: git add 加入暂存 git status 查看状态 git status -s 状态概览 git diff 尚未暂存的文件 git diff --staged 暂存区文件 git commit 提交更新 git reset 回滚 git rm 从版本库中移除 git rm --cached README 从暂存区中移除 git mv 相当于mv git rm git add 三个命令 使用演示: [root@linux-node1 test]# touch index.html ==>创建文件 [root@linux-node1 test]# vim index.html [root@linux-node1 test]# git status ==>此时文件处于工作目录中 位于分支 master 初始提交 未跟踪的文件: (使用 "git add <文件>..." 以包含要提交的内容) index.html 提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪) [root@linux-node1 test]# git add index.html ==>加入代码库 [root@linux-node1 test]# git status ==>此时文件处于暂存区 位于分支 master 初始提交 要提交的变更: (使用 "git rm --cached <文件>..." 以取消暂存) 新文件: index.html [root@linux-node1 test]# git commit -m "first commit" ==>提交到本地仓库 [master(根提交) c6bc04f] first commit 1 file changed, 3 insertions(+) create mode 100644 index.html [root@linux-node1 test]# git status 位于分支 master 无文件要提交,干净的工作区 [root@linux-node1 test]# git log commit c6bc04f90d4ef442e2c4d5bc788b21de239332da ==>回滚需要的id Author: ****** <******@qq.com> Date: Fri Dec 8 22:37:40 2017 +0800 first commit [root@linux-node1 test]# touch pay.html [root@linux-node1 test]# vim pay.html [root@linux-node1 test]# git add pay.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html [root@linux-node1 test]# touch news.html [root@linux-node1 test]# echo "123" > news.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html Untracked files: (use "git add <file>..." to include in what will be committed) news.html [root@linux-node1 test]# git add news.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: news.html new file: pay.html [root@linux-node1 test]# git rm --cached pay.html #将pay.html从暂存区移除 rm 'pay.html' [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: news.html Untracked files: (use "git add <file>..." to include in what will be committed) pay.html [root@linux-node1 test]# git commit -m "news" [master d83603a] news 1 file changed, 1 insertion(+) create mode 100644 news.html [root@linux-node1 test]# git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) pay.html nothing added to commit but untracked files present (use "git add" to track) [root@linux-node1 test]# git log commit d83603a56b8926630d31b46898e4b6d69293d946 Author:******** Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ***************** Date: Fri Dec 8 22:37:40 2017 +0800 first commit [root@linux-node1 test]# echo "66666" >> pay.html [root@linux-node1 test]# git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) pay.html nothing added to commit but untracked files present (use "git add" to track) [root@linux-node1 test]# git add pay.html [root@linux-node1 test]# git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: pay.html [root@linux-node1 test]# git commit -m "pay modelue" [master e55a302] pay modelue 1 file changed, 2 insertions(+) create mode 100644 pay.html [root@linux-node1 test]# git status On branch master nothing to commit, working directory clean [root@linux-node1 test]# git log commit e55a302e11d967fd25eac1cce8b6c7bed732019b Author:****************** Date: Fri Dec 8 22:49:57 2017 +0800 pay modelue commit d83603a56b8926630d31b46898e4b6d69293d946 Author: ****************** Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ****************** Date: Fri Dec 8 22:37:40 2017 +0800 first commit
-
2、分支管理
[root@linux-node1 test]# git status On branch master nothing to commit, working directory clean 建分支,开发新功能是不能在master分支上开发 [root@linux-node1 test]# git branch about #创建分支 [root@linux-node1 test]# git status On branch master nothing to commit, working directory clean [root@linux-node1 test]# git checkout about #切换分支 Switched to branch 'about' [root@linux-node1 test]# git status On branch about nothing to commit, working directory clean [root@linux-node1 test]# git log #创建的分支是在master分支当前的状态进行创建的。所以在about分支上也会有master的记录 commit e55a302e11d967fd25eac1cce8b6c7bed732019b Author: ************ Date: Fri Dec 8 22:49:57 2017 +0800 pay modelue commit d83603a56b8926630d31b46898e4b6d69293d946 Author: ************ Date: Fri Dec 8 22:48:37 2017 +0800 news commit c6bc04f90d4ef442e2c4d5bc788b21de239332da Author: ************ Date: Fri Dec 8 22:37:40 2017 +0800 first commit [root@linux-node1 test]# git branch * about master [root@linux-node1 test]# touch about.html [root@linux-node1 test]# echo "about us" >> about.html [root@linux-node1 test]# git add . [root@linux-node1 test]# git commit -m "about" [about 08b200a] about 1 file changed, 1 insertion(+) create mode 100644 about.html [root@linux-node1 test]# git log [root@linux-node1 test]# git checkout master #切换到master分支 Switched to branch 'master' [root@linux-node1 test]# git log [root@linux-node1 test]# git checkout about #切换到about分支 [root@linux-node1 test]# echo "about2" > about2.html [root@linux-node1 test]# git add . [root@linux-node1 test]# git commit -m "about2" [root@linux-node1 test]# git log [root@linux-node1 test]# git checkout master [root@linux-node1 test]# git log [root@linux-node1 test]# git merged about #在master分支上合并about分支 [root@linux-node1 test]# git log [root@linux-node1 test]# git branch test #创建test分支 [root@linux-node1 test]# git checkout test [root@linux-node1 test]# touch "test" > test.html [root@linux-node1 test]# git add . [root@linux-node1 test]# git commit -m "test" [root@linux-node1 test]# git checkout master [root@linux-node1 test]# git branch --merged #查看已经合并的分支 [root@linux-node1 test]# git branch --no-merged #查看未合并的分支 分支命令 git branch例出分支 git branch -v git branch --merged查看哪些分支被合并 git branch --no-merged查看哪些分支未被合并 git branch -d testling删除分支 git checkout切换分支 git merged融合分支,
-
1、安装依赖及gitlab
[root@linux-node1 ~]# yum install -y curl policycoreutils openssh-server openssh-clients postfix [root@linux-node1 ~]# systemctl start postfix
-
2、安装gitlab
由于国内网络偏慢,这里使用清华大学的镜像源进行安装gitlab-ce [root@linux-node1 ~]# cat /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 repo_gpgcheck=0 gpgcheck=0 enabled=1 gpgkey= [root@linux-node1 ~]# yum makecache [root@linux-node1 ~]# yum install -y gitlab-ce
-
3、修改配置文件
[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb external_url 'http://192.168.56.11' [root@linux-node1 ~]# gitlab-ctl reconfigure 这一步时间比较长,耐心等待 gitlab常用命令: 关闭gitlab:[root@linux-node1 ~]# gitlab-ctl stop 启动gitlab:[root@linux-node1 ~]# gitlab-ctl start 重启gitlab:[root@linux-node1 ~]# gitlab-ctl restart 重载配置文件: gitlab-ctl reconfigure
可以使用gitlab-ctl
管理gitlab,例如查看gitlab状态:
[root@linux-node1 ~]# gitlab-ctl status run: gitaly: (pid 53207) 176s; run: log: (pid 52331) 647s run: gitlab-monitor: (pid 53233) 174s; run: log: (pid 52406) 620s run: gitlab-workhorse: (pid 53189) 180s; run: log: (pid 52274) 671s run: logrotate: (pid 52307) 654s; run: log: (pid 52306) 654s run: nginx: (pid 53694) 2s; run: log: (pid 52285) 665s run: node-exporter: (pid 52388) 631s; run: log: (pid 52387) 631s run: postgres-exporter: (pid 53262) 171s; run: log: (pid 52478) 581s run: postgresql: (pid 52013) 855s; run: log: (pid 52012) 855s run: prometheus: (pid 53245) 172s; run: log: (pid 52443) 598s run: redis: (pid 51951) 867s; run: log: (pid 51950) 867s run: redis-exporter: (pid 52426) 609s; run: log: (pid 52425) 609s run: sidekiq: (pid 52256) 677s; run: log: (pid 52255) 677s run: unicorn: (pid 52218) 683s; run: log: (pid 52217) 683s 提示:gitlab需要使用到80端口,所以得保证80端口不被占用 [root@linux-node1 ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 963 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 1156 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 1392 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 1544 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 22057 root 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 22793 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 23247 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 23367 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 26356 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 64149 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) httpd 64641 apache 4u IPv6 56349 0t0 TCP *:http (LISTEN) [root@linux-node1 ~]# systemctl stop httpd [root@linux-node1 ~]# gitlab-ctl restart ok: run: gitaly: (pid 55012) 0s ok: run: gitlab-monitor: (pid 55022) 1s ok: run: gitlab-workhorse: (pid 55025) 0s ok: run: logrotate: (pid 55034) 1s ok: run: nginx: (pid 55036) 0s ok: run: node-exporter: (pid 55046) 1s ok: run: postgres-exporter: (pid 55051) 0s ok: run: postgresql: (pid 55059) 1s ok: run: prometheus: (pid 55066) 0s ok: run: redis: (pid 55072) 0s ok: run: redis-exporter: (pid 55081) 0s ok: run: sidekiq: (pid 55105) 0s ok: run: unicorn: (pid 55112) 0s [root@linux-node1 ~]# lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 54794 root 8u IPv4 1562548 0t0 TCP *:http (LISTEN) nginx 54802 gitlab-www 8u IPv4 1562548 0t0 TCP *:http (LISTEN)
-
4、浏览器访问登录:
安装完成!
,
-
1.创建Group,User,Project
创建一个组,组名为java
Group path http://192.168.56.11/java Visibility Level: #为权限级别,一般使用Private Private Internal Public
创建一个PM的用户作为项目管理者并加入到java组内
创建一个项目:
创建dev1和dev2的用户作为开发者,并加入到项目中
-
2.测试dev1,dev2拉取代码库
(1)生成ssh-key [root@linux-node1 ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Hf3O9F7sS9N04cFUr3Awb/Wec28gTpHYyRZMCzLW9q0 root@linux-node1 The key's randomart image is: +---[RSA 2048]----+ | +..o= .+| | . oo*.Oo.o| | .o.@.++o| | . o.*oo+| | S . o.=+=| | oE= =*| | . ooB| | .+o| | .+| +----[SHA256]-----+ [root@linux-node1 ~]# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLDVIqTAvJtj8Uc+SvhcKOKuDtURt3YBxHo9enUkDjOWtSygLZI4hSrEsnvjHdnxeBGOgjPrxEfMMdNCno4pox7V/8bIU9LRVp2eeQFS+N+bSmbJlTKyODa0tabPwT7URYoiFI3giQamQdA0AwwPCPM/RcXwHJsw4q0O/2woCqNKq2tHaUFBqojd2KvqavzpB+4+AdKJSoabwLhE8dzfjIR/eHY31Y2C/+m9sU504v+R0GsAqr5uifi6Ct9eFvumI54BvHssIpZFZmADTT35b1aP0WSwZb2VEhXjaia8L6h/6ANn1NuHGgYZqNiYT6JILESKbrc7PyJOn9DfHKSMq9 root@linux-node1 (2)将公钥(id_rsa.pub)放进dev1账户中 在admin账户下给dev1,dev2账户设置密码,然后使用dev1登录gitlab,做如下操作添加ssh-key: 测试是否能正常拉取代码库app1 [root@linux-node1 ~]# git clone git@192.168.56.11:java/app1.git Cloning into 'app1'... The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established. ECDSA key fingerprint is SHA256:p2lhKmsPQ6K+dWHHvbJg0GV+Ni9VM7vlViKrYsZLP1s. ECDSA key fingerprint is MD5:22:14:1c:37:de:47:1c:4a:2f:88:b1:dc:e2:d0:02:17. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.56.11' (ECDSA) to the list of known hosts. warning: You appear to have cloned an empty repository. Checking connectivity... done. [root@linux-node1 ~]# ll total 6804 -rw-------. 1 root root 948 Dec 3 01:21 anaconda-ks.cfg drwxr-xr-x 3 root root 17 Dec 20 15:00 app1 drwxr-xr-x 22 root root 24576 Dec 8 22:16 git-2.7.4 drwxr-xr-x 3 root root 65 Dec 9 01:23 test -rw-r--r-- 1 root root 6918037 Dec 8 22:09 v2.7.4.zip [root@linux-node1 ~]# cd app1 [root@linux-node1 app1]# ll total 4 -rw-r--r-- 1 root root 19 Dec 20 15:05 readme
到此,Linux环境下完成了gitlab的授权管理代码库。
下面以PM用户进行创建开发计划
开发一个官网V1.0版本,包含首页和新闻
(1)创建里程碑(Milestone)
(2)依次把任务首页,新闻添加到里程碑,并进行任务分配给开发者
(3)使用dev1用户登录查看,会有任务提示,如图:
(4)dev1开发者收到任务,进行开发
[root@linux-node1 app1]# git checkout -b shouye #创建首页分支 Switched to a new branch 'shouye' [root@linux-node1 app1]# git status On branch shouye nothing to commit, working directory clean [root@linux-node1 app1]# echo "<h1> welcome to www.123.com" > index.html #进行开发 [root@linux-node1 app1]# ll total 8 -rw-r--r-- 1 root root 28 Dec 20 15:50 index.html -rw-r--r-- 1 root root 19 Dec 20 15:05 readme [root@linux-node1 app1]# git add . [root@linux-node1 app1]# git commit -m "shouye" #开发完成,提交本地仓库 [shouye babdcb5] shouye 1 file changed, 1 insertion(+) create mode 100644 index.html [root@linux-node1 app1]# git push origin shouye #提交到远程库 Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: To create a merge request for shouye, visit: remote: http://192.168.56.11/java/app1/merge_requests/new?merge_request%5Bsource_branch%5D=shouye remote: To git@192.168.56.11:java/app1.git * [new branch] shouye -> shouye 可以看到有刚才创建的分支,点击"merge request"合并分支请求,之后PM用户登录处理合并请求。此时,一个功能的开发流程就完成。
总结:
-
PM在gitlab创建任务,分配给开发人员
-
开发人员领取任务后,在本地使用git clone拉取代码库
-
开发人员创建开发分支(git checkout -b dev),并进行开发
-
开发人员完成之后,提交到本地仓库(git commit )
-
开发人员在gitlab界面上申请分支合并请求(Merge request)
-
PM在gitlab上查看提交和代码修改情况,确认无误后,确认将开发人员的分支合并到主分支(master)
-
开发人员在gitlab上Mark done确认开发完成,并关闭issue。这一步在提×××并请求时可以通过描述中填写"close #1"等字样,可以直接关闭issue。
-
gitlab的备份和恢复
(1)创建备份目录,并授权
[root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-node1 ~]# chown -R git.git /data/ [root@linux-node1 ~]# ll /data/ -d drwxr-xr-x 3 git git 20 Dec 20 16:21 /data/
(2)修改gitlab配置
[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb gitlab_rails['backup_path'] = "/data/backups/gitlab" #备份路径 gitlab_rails['backup_keep_time'] = 604800 #备份7天
[root@linux-node1 ~]# gitlab-ctl reconfigure [root@linux-node1 ~]# gitlab-ctl restart ok: run: gitaly: (pid 41722) 0s ok: run: gitlab-monitor: (pid 41735) 1s ok: run: gitlab-workhorse: (pid 41738) 0s ok: run: logrotate: (pid 41748) 0s ok: run: nginx: (pid 41755) 0s ok: run: node-exporter: (pid 41757) 0s ok: run: postgres-exporter: (pid 41765) 0s ok: run: postgresql: (pid 41792) 0s ok: run: prometheus: (pid 41795) 0s ok: run: redis: (pid 41807) 0s ok: run: redis-exporter: (pid 41812) 1s ok: run: sidekiq: (pid 41822) 0s ok: run: unicorn: (pid 41831) 0s
(3)备份
[root@linux-node1 ~]# gitlab-rake gitlab:backup:create Dumping database ... Dumping PostgreSQL database gitlabhq_production ... [DONE] done Dumping repositories ... * java/app1 ... [DONE] * java/app1.wiki ... [SKIPPED] done Dumping uploads ... done Dumping builds ... done Dumping artifacts ... done Dumping pages ... done Dumping lfs objects ... done Dumping container registry images ... [DISABLED] Creating backup archive: 1513759548_2017_12_20_10.2.4_gitlab_backup.tar ... done Uploading backup archive to remote storage ... skipped Deleting tmp directories ... done done done done done done done done Deleting old backups ... done. (0 removed)
(4)查看备份目录
[root@linux-node1 ~]# ll /data/backups/gitlab/ total 72 -rw------- 1 git git 71680 Dec 20 16:45 1513759548_2017_12_20_10.2.4_gitlab_backup.tar #1513759548_2017_12_20_10.2.4为时间戳,备份的时候用的着
(5)恢复备份
删除gitlab中的app1的项目,再恢复 停止数据写入服务: [root@linux-node1 ~]# gitlab-ctl stop unicorn [root@linux-node1 ~]# gitlab-ctl stop sidekiq 恢复数据: [root@linux-node1 ~]# gitlab-rake gitlab:backup:restore BACKUP=1513759548_2017_12_20_10.2.4 [root@linux-node1 ~]# gitlab-ctl restart ok: run: gitaly: (pid 45486) 0s ok: run: gitlab-monitor: (pid 45502) 0s ok: run: gitlab-workhorse: (pid 45507) 1s ok: run: logrotate: (pid 45525) 0s ok: run: nginx: (pid 45531) 1s ok: run: node-exporter: (pid 45536) 0s ok: run: postgres-exporter: (pid 45540) 1s ok: run: postgresql: (pid 45547) 0s ok: run: prometheus: (pid 45555) 1s ok: run: redis: (pid 45562) 0s ok: run: redis-exporter: (pid 45568) 1s ok: run: sidekiq: (pid 45572) 0s ok: run: unicorn: (pid 45614) 0s
此时即可恢复原来的项目
邮件配置: gitlab_rails['time_zone'] = 'Asia/Shanghai' gitlab_rails['gitlab_email_enabled'] = true gitlab_rails['gitlab_email_from'] = 'xiaoming@126.com' gitlab_rails['gitlab_email_display_name'] = 'gitlab' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.126.com" gitlab_rails['smtp_port'] = 25 gitlab_rails['smtp_user_name'] = "xiaoming" gitlab_rails['smtp_password'] = "your password" gitlab_rails['smtp_domain'] = "126.com" gitlab_rails['smtp_authentication'] = "login",
命令行测试
[root@linux-node1 ~]# mkdir testing [root@linux-node1 ~]# [root@linux-node1 ~]# cd testing/ [root@linux-node1 testing]# [root@linux-node1 testing]# git init Initialized empty Git repository in /root/testing/.git/ [root@linux-node1 testing]# echo "123" > index.html [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "first commit" [master (root-commit) b712131] first commit 1 file changed, 1 insertion(+) create mode 100644 index.html [root@linux-node1 testing]# echo "a file" > a.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "add a.txt" [master 025e8a3] add a.txt 1 file changed, 1 insertion(+) create mode 100644 a.txt [root@linux-node1 testing]# echo "b file" > b.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "add b.txt" [master f4b13b6] add b.txt 1 file changed, 1 insertion(+) create mode 100644 b.txt [root@linux-node1 testing]# git log commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# git checkout -b dev Switched to a new branch 'dev' [root@linux-node1 testing]# git status On branch dev nothing to commit, working directory clean [root@linux-node1 testing]# git log commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# echo "welcome to beijing" > test1.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "test1" [dev d224e8c] test1 1 file changed, 1 insertion(+) create mode 100644 test1.txt [root@linux-node1 testing]# echo "welcome to shanghai" > test2.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "test2" [dev e254dd5] test2 1 file changed, 1 insertion(+) create mode 100644 test2.txt [root@linux-node1 testing]# git log commit e254dd5657d99ed287faf62f74b566a7ac1bf858 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:26:01 2017 +0800 test2 commit d224e8cb4a51a65377c8d8eb75c3613b197e47a4 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:25:37 2017 +0800 test1 commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# git checkout master Switched to branch 'master' [root@linux-node1 testing]# git status On branch master nothing to commit, working directory clean [root@linux-node1 testing]# echo "master1" > master1.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "master1" [master 1ebe653] master1 1 file changed, 1 insertion(+) create mode 100644 master1.txt [root@linux-node1 testing]# echo "master2" > master2.txt [root@linux-node1 testing]# git add . [root@linux-node1 testing]# git commit -m "master2" [master 814b217] master2 1 file changed, 1 insertion(+) create mode 100644 master2.txt [root@linux-node1 testing]# git log commit 814b217ae84ca4ad541c36d96e9b3c2744bca849 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:28:15 2017 +0800 master2 commit 1ebe65348f73958eeafce158f922d83e386faa78 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:27:50 2017 +0800 master1 commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit [root@linux-node1 testing]# git merge dev Merge made by the 'recursive' strategy. test1.txt | 1 + test2.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 test1.txt create mode 100644 test2.txt [root@linux-node1 testing]# git log commit df1da42a6c93152001199d684f01702eb6cb622f Merge: 814b217 e254dd5 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:29:35 2017 +0800 Merge branch 'dev' commit 814b217ae84ca4ad541c36d96e9b3c2744bca849 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:28:15 2017 +0800 master2 commit 1ebe65348f73958eeafce158f922d83e386faa78 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:27:50 2017 +0800 master1 commit e254dd5657d99ed287faf62f74b566a7ac1bf858 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:26:01 2017 +0800 test2 commit d224e8cb4a51a65377c8d8eb75c3613b197e47a4 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:25:37 2017 +0800 test1 commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:36 2017 +0800 add b.txt commit 025e8a337bfe312065d93b040852ceb532ef6642 Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:22:12 2017 +0800 add a.txt commit b712131d81e3224f72f97c76f855e28da413450e Author: xiaoming <xiaoming@163.com> Date: Thu Dec 21 14:21:35 2017 +0800 first commit
此时,整个分支合并图如下:
分支的状态会保留
如果使用git rebase dev,分支合并图如下:
分支的状态会清除
