22.1 代码管理平台介绍html
版本控制,记录若干文件内容变化,以便未来查阅特定版本修订状况java
版本管理工具发展简史,cvs—> svn—> git 参考http://luckypoem14.github.io/test/2012/04/24/scm-history/node
svn全称subversion,是一个开源版本控制系统,始于2000年mysql
git是linux创始人linus发起的,2005年发布,最初目的是更好管理linux内核代码linux
git和svn不一样在于git不须要依赖服务端就能够工做,即git是分布式的nginx
关于git和svn的比较你们参考http://blog.lishiming.net/?p=305git
github是基于git的在线web页面代码托管平台,能够选择付费服务github
gitlab能够认为是一个开源的github,二者没有直接关系web
22.2 安装svnredis
一、安装服务端
[root@arslinux-01 ~]# yum install -y subversion
二、建立版本库
[root@arslinux-01 ~]# mkdir -p /data/svnroot/myproject [root@arslinux-01 ~]# svnadmin create /data/svnroot/myproject/ [root@arslinux-01 ~]# cd /data/svnroot/myproject/conf/ [root@arslinux-01 conf]# ls authz passwd svnserve.conf
[root@arslinux-01 conf]# vim authz admins = arslinux,user1 [/] @admins = rw *= r [myproject:/] user1 = rw
[/] /指的就是/data/svnroot/myproject/,在这个目录下 admin 组权限时 rw
* 表示剩余的人是 r 权限
[myproject:/] 通常用在 svnroot 下有多个项目的状况下,其中一个 myproject 的项目
能够在这个目录下建立子目录 / 前面 : 表示 myproject 是个项目名
三、设置密码
[root@arslinux-01 conf]# vim passwd [users] arslinux = arslinux_!(*$123 user1 = user1_^^^123 user2 = user2-***123
四、编辑配置文件 svnserver.conf
[root@arslinux-01 conf]# vim svnserve.conf [general] anon-access = none //匿名用户有无权限 auth-access = write //被受权用户 可写 password-db = passwd //用户密码存在哪里 authz-db = authz //权限控制文件 realm = /data/svnroot/myproject //对哪一个项目生效
五、启动 svn
[root@arslinux-01 conf]# svnserve -d -r /data/svnroot/
-d 后台启动
-r 指定项目所在路径,也可写成 svnserve -d -r /data/svnroot/myproject/
[root@arslinux-01 conf]# ps aux|grep svnserve root 31030 0.0 0.0 180732 804 ? Ss 22:24 0:00 svnserve -d -r /data/svnroot/ root 31060 0.0 0.0 112724 988 pts/1 S+ 22:26 0:00 grep --color=auto svnserve [root@arslinux-01 conf]# netstat -lntp|grep svnserve tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 31030/svnserve
22.3 客户端上使用svn(linux)
一、客户端安装 subversion
[root@arslinux-02 ~]# yum install -y subversion
二、链接 svn 服务器(本地能够保存用户名和密码)
[root@arslinux-02 ~]# cd /home/ [root@arslinux-02 home]# svn checkout svn://192.168.194.130/myproject --username=user1 认证领域: <svn://192.168.194.130:3690> /data/svnroot/myproject “user1”的密码: ----------------------------------------------------------------------- 注意! 你的密码,对于认证域: <svn://192.168.194.130:3690> /data/svnroot/myproject 只能明文保存在磁盘上! 若是可能的话,请考虑配置你的系统,让 Subversion 能够保存加密后的密码。请参阅文档以得到详细信息。 你能够经过在“/root/.subversion/servers”中设置选项“store-plaintext-passwords”为“yes”或“no”, 来避免再次出现此警告。 ----------------------------------------------------------------------- 保存未加密的密码(yes/no)?yes 取出版本 0。
三、 拷贝任意一个文件到项目中
[root@arslinux-02 home]# cd myproject/ [root@arslinux-02 myproject]# cp /etc/fstab ..
四、添加到版本控制中心 svn add .
[root@arslinux-02 myproject]# svn add ./fstab A fstab
五、把文件上传到服务器 svn commit -m "add file"
[root@arslinux-02 myproject]# svn commit -m "add fstab" 正在增长 fstab 传输文件数据. 提交后的版本为 1。
六、在服务端上升级版本才能看见上传的文件
把当前目录下的文件都更新到最新版 svn update 可简写为 svn up
[root@arslinux-01 svntest]# cd myproject/ [root@arslinux-01 myproject]# ls [root@arslinux-01 myproject]# svn up 正在升级 '.': A fstab 更新到版本 1。 [root@arslinux-01 myproject]# ls fstab
七、用户名密码被记录在 /root/.subversion/auth/svn.simple/ 下
[root@arslinux-02 .subversion]# cat /root/.subversion/auth/svn.simple/7681a1260e61438030ce66c9a673594d K 8 passtype V 6 simple K 8 password V 12 user1_^^^123 K 15 svn:realmstring V 52 <svn://192.168.194.130:3690> /data/svnroot/myproject K 8 username V 5 user1 END
八、若是不想用户信息被记录,能够删除 svn.simple 下的文件便可
[root@arslinux-01 svn.simple]# rm -rf /root/.subversion/auth/svn.simple/7681a1260e61438030ce66c9a673594d
九、在客户端更改文件,添加任意一行到 fstab,并将更改数据上传服务端
[root@arslinux-02 myproject]# echo '"xafdasfasdfsa" >> fstab [root@arslinux-02 myproject]# svn commit -m "ch fstab" 正在发送 fstab 传输文件数据. 提交后的版本为 2。
十、服务端再更新版本,发现须要密码(提示输入 root 密码,可回车跳过,输入实际用户名密码)
[root@arslinux-01 myproject]# svn up 正在升级 '.': 认证领域: <svn://192.168.194.130:3690> /data/svnroot/myproject “root”的密码: 认证领域: <svn://192.168.194.130:3690> /data/svnroot/myproject 用户名: arslinux “arslinux”的密码: ----------------------------------------------------------------------- 注意! 你的密码,对于认证域: <svn://192.168.194.130:3690> /data/svnroot/myproject 只能明文保存在磁盘上! 若是可能的话,请考虑配置你的系统,让 Subversion 能够保存加密后的密码。请参阅文档以得到详细信息。 你能够经过在“/root/.subversion/servers”中设置选项“store-plaintext-passwords”为“yes”或“no”, 来避免再次出现此警告。 ----------------------------------------------------------------------- 保存未加密的密码(yes/no)?yes U fstab 更新到版本 2。
十一、文件最后一行也增长了刚才输入的随机字符串
[root@arslinux-01 myproject]# tail -1 fstab xafdasfasdfsa
十二、在服务端本地删除文件,服务器上删除文件
[root@arslinux-01 myproject]# svn delete fstab D fstab [root@arslinux-01 myproject]# svn commit -m "delete fstab" 正在删除 fstab 提交后的版本为 3。
1三、在客户端上更新同步
[root@arslinux-02 myproject]# svn up 正在升级 '.': D fstab 更新到版本 3。 [root@arslinux-02 myproject]# ls
1四、查看变动历史 svn log
[root@arslinux-02 myproject]# svn log ------------------------------------------------------------------------ r3 | arslinux | 2019-07-22 22:06:45 +0800 (一, 2019-07-22) | 1 行 delete fstab ------------------------------------------------------------------------ r2 | user1 | 2019-07-22 21:43:42 +0800 (一, 2019-07-22) | 1 行 ch fstab ------------------------------------------------------------------------ r1 | user1 | 2019-07-22 21:22:41 +0800 (一, 2019-07-22) | 1 行 add fstab
svn: E155015: 提交失败(细节以下) 解决办法:
svn resolved <文件名>
22.4 客户端上使用svn(windows)
下载 TortoiseSVN 并安装 https://tortoisesvn.net/index.zh.html
一、安装完软件,再安装语言包便可
二、硬盘里新建 myproject 文件夹
三、右击 myproject 文件夹,选择 SVN Checkout...
四、填入项目的服务地址
五、点 OK 后,输入用户名和密码
五、在 myproject 文件夹下新建 123.txt,内容随便
六、右击 123.txt,选择 TortoiseSVN——Add
七、右击 123.txt,SVN Commit...
八、在弹框中作一些说明
九、在 linux 服务端机器
[root@arslinux-01 myproject]# svn up 正在升级 '.': A 123.txt 更新到版本 6。 [root@arslinux-01 myproject]# cat 123.txt adsfadfasdfa
十、在另外一个linux客户端的机器上编辑一个文件并上传
[root@arslinux-02 myproject]# echo "adfadfafa\nadsfdafa" > ars4life [root@arslinux-02 myproject]# cat ars4life adfadfafa\nadsfdafa [root@arslinux-02 myproject]# svn add ars4life A ars4life [root@arslinux-02 myproject]# svn commit -m "add asr4life" 正在增长 ars4life 传输文件数据. 提交后的版本为 7。
十一、而后在 windows 机器上,右击 myproject ,选择 SVN Update,myproject 目录里会有 ars4life 文件
简明教程:http://www.jianshu.com/p/6b3b7b915332
22.5/22.6 单机上使用git
一、安装
[root@arslinux-01 ~]# yum install -y git
二、建立 gitroot目录
[root@arslinux-01 ~]# mkdir /data/gitroot/ [root@arslinux-01 ~]# cd !$ cd /data/gitroot/ [root@arslinux-01 gitroot]#
三、初始化仓库
[root@arslinux-01 gitroot]# git init 初始化空的 Git 版本库于 /data/gitroot/.git/ [root@arslinux-01 gitroot]# ll -a 总用量 0 drwxrwxr-x 3 root root 18 7月 23 22:18 . drwxr-xr-x 11 root root 135 7月 23 22:18 .. drwxrwxr-x 7 root root 119 7月 23 22:18 .git
4.在库中建立一个文件,任意内容
[root@arslinux-01 gitroot]# echo "dasfdafasfafas" > 1.txt [root@arslinux-01 gitroot]# echo "ddfdfdfw22ghghg" >> 1.txt [root@arslinux-01 gitroot]# echo "dftyuoiuoryfhgjg" >> 1.txt
五、将文件添加到仓库(方法几乎和 svn 一致)
[root@arslinux-01 gitroot]# git add 1.txt [root@arslinux-01 gitroot]# git commit -m "add 1.txt" *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'root@arslinux-01.(none)')
六、上传时出错,根据参考内容,设置邮箱和用户名
[root@arslinux-01 gitroot]# git config --global user.email "zy77xp2316@qq.com" [root@arslinux-01 gitroot]# git config --global user.name "arslinux"
也能够去 /root/.gitconfig 下更改
七、从新作上传
[root@arslinux-01 gitroot]# git commit -m "add 1.txt" [master(根提交) f04992b] add 1.txt 1 file changed, 3 insertions(+) create mode 100644 1.txt
八、更改 1.txt 内容
[root@arslinux-01 gitroot]# echo "888888" >> 1.txt [root@arslinux-01 gitroot]# echo "777777" >> 1.txt
九、修改的内容若是提交上传,还须要操做 git add 和 git commit -a
[root@arslinux-01 gitroot]# git add 1.txt [root@arslinux-01 gitroot]# git commit -m "add 1.txt" [master 03d2ada] add 1.txt 1 file changed, 2 insertions(+)
十、查看当前仓库中的状态,好比是否有改动的文件
[root@arslinux-01 gitroot]# git status # 位于分支 master 无文件要提交,干净的工做区
十一、若是没有 git add 和 git commit 的步骤,会提示
[root@arslinux-01 gitroot]# echo " dasfadsf a" >> 1.txt [root@arslinux-01 gitroot]# git status # 位于分支 master # 还没有暂存以备提交的变动: # (使用 "git add <file>..." 更新要提交的内容) # (使用 "git checkout -- <file>..." 丢弃工做区的改动) # #修改: 1.txt # 修改还没有加入提交(使用 "git add" 和/或 "git commit -a")
十二、对比修改了哪些内容能够用 git diff
[root@arslinux-01 gitroot]# git diff diff --git a/1.txt b/1.txt index 03086e7..e51c67f 100644 --- a/1.txt +++ b/1.txt @@ -3,3 +3,4 @@ ddfdfdfw22ghghg dftyuoiuoryfhgjg 888888 777777 + dasfadsf a
1三、再作几回操做,查看全部提交记录
[root@arslinux-01 gitroot]# vim 1.txt 增长一行 [root@arslinux-01 gitroot]# git add 1.txt [root@arslinux-01 gitroot]# git commit -m "add 1.txt" [master 3517c53] add 1.txt 1 file changed, 2 insertions(+) [root@arslinux-01 gitroot]# vim 1.txt 删除一行 [root@arslinux-01 gitroot]# git add 1.txt [root@arslinux-01 gitroot]# git commit -m "ch 1.txt" [master b68b8fb] ch 1.txt 1 file changed, 1 deletion(-)
查看提交记录
[root@arslinux-01 gitroot]# git log commit b68b8fb900160e2ab06b4204d97f659fa14fa26a Author: arslinux <xxxxxx@qq.com> Date: Tue Jul 23 22:45:24 2019 +0800 ch 1.txt commit 3517c53c22f14c345206324bf9d190f157ec1f83 Author: arslinux <xxxxxx@qq.com> Date: Tue Jul 23 22:44:55 2019 +0800 add 1.txt commit 03d2adacc5ee700de75799b90c1534ad6d9e6b9a Author: arslinux <xxxxxx@qq.com> Date: Tue Jul 23 22:36:19 2019 +0800 add 1.txt commit f04992b2e67da3ac3bfbc1c6a21053312f27ac76 Author: arslinux <xxxxxx@qq.com> Date: Tue Jul 23 22:29:07 2019 +0800 add 1.txt
只显示一行信息 git log --pretty=oneline
[root@arslinux-01 gitroot]# git log --pretty=oneline b68b8fb900160e2ab06b4204d97f659fa14fa26a ch 1.txt 3517c53c22f14c345206324bf9d190f157ec1f83 add 1.txt 03d2adacc5ee700de75799b90c1534ad6d9e6b9a add 1.txt f04992b2e67da3ac3bfbc1c6a21053312f27ac76 add 1.txt
1四、git reset --hard 字符串 回退版本,其中后面跟的字符串是简写
[root@arslinux-01 gitroot]# git reset --hard 3517c5 HEAD 如今位于 3517c53 add 1.txt [root@arslinux-01 gitroot]# git log --pretty=oneline 3517c53c22f14c345206324bf9d190f157ec1f83 add 1.txt 03d2adacc5ee700de75799b90c1534ad6d9e6b9a add 1.txt f04992b2e67da3ac3bfbc1c6a21053312f27ac76 add 1.txt
1五、若是回退出了错,如今想回到 b68b8fb900 的版本
能够直接 git reset --hard b68b8fb900,也可使用 git reflog
[root@arslinux-01 gitroot]# git reflog 3517c53 HEAD@{0}: reset: moving to 3517c5 b68b8fb HEAD@{1}: commit: ch 1.txt 3517c53 HEAD@{2}: commit: add 1.txt 03d2ada HEAD@{3}: commit: add 1.txt f04992b HEAD@{4}: commit (initial): add 1.txt
而后在使用 git reset --hard b68b8fb
1六、若是不当心删除了文件,那么用 git checkout -- 文件名 来恢复
[root@arslinux-01 gitroot]# rm -rf 1.txt [root@arslinux-01 gitroot]# ls [root@arslinux-01 gitroot]# git checkout -- 1.txt [root@arslinux-01 gitroot]# ls 1.txt
1七、若是文件本修改,add 后没有 commit,想回到上一次提交的状态,可使用 git reset HEAD 文件名,而后在执行git checkout -- 文件名
[root@arslinux-01 gitroot]# git add 1.txt [root@arslinux-01 gitroot]# git reset HEAD 1.txt 重置后撤出暂存区的变动: M1.txt [root@arslinux-01 gitroot]# git checkout -- 1.txt
两个步骤:
1)git reset HEAD 文件名 从缓存区撤销
2)git checkout -- 文件名 恢复成修改前的状态
1八、删除文件
[root@arslinux-01 gitroot]# git rm 1.txt rm '1.txt' [root@arslinux-01 gitroot]# git commit -m "delete 1.txt" [master 560134a] delete 1.txt 1 file changed, 7 deletions(-) delete mode 100644 1.txt [root@arslinux-01 gitroot]# ls [root@arslinux-01 gitroot]# git checkout -- 1.txt error: pathspec '1.txt' did not match any file(s) known to git.
1九、文件删除后依然能够找回,用 git reset 找回
[root@arslinux-01 gitroot]# git log --pretty=oneline 560134a1708b3815cb53af6ae160240b574e2240 delete 1.txt 3517c53c22f14c345206324bf9d190f157ec1f83 add 1.txt 03d2adacc5ee700de75799b90c1534ad6d9e6b9a add 1.txt f04992b2e67da3ac3bfbc1c6a21053312f27ac76 add 1.txt [root@arslinux-01 gitroot]# git reset --hard 3517c53c22f1 HEAD 如今位于 3517c53 add 1.txt [root@arslinux-01 gitroot]# ls 1.txt
22.7 创建远程仓库
一、首先到 https://github.com 注册一个帐号,建立本身的git,点右上角 “+”,选择 New repository
二、仓库名字自定义,好比叫,能够添加注释(Description),权限选择public,点Create repository
三、添加key:右上角点本身头像,选择settings,左侧选择SSH and GPG keys
四、右侧点 New SSH key,把linux机器上的 ~/.ssh/id_rsa.pub 内容粘贴到这里,能够用 ssh-keygen 生成
五、在本地建立一个仓库并进入
[root@arslinux-01 ~]# mkdir /tmp/studygit/ [root@arslinux-01 ~]# cd /tmp/studygit/
六、根据提示进行操做,首先建立一个 README.md
[root@arslinux-01 studygit]# echo "# studygit" >> README.md
七、初始化,生成 .git
[root@arslinux-01 studygit]# git init 初始化空的 Git 版本库于 /tmp/studygit/.git/ [root@arslinux-01 studygit]# ll -a 总用量 4 drwxrwxr-x 3 root root 80 7月 25 22:05 . drwxrwxrwt 11 root root 340 7月 25 22:05 .. drwxrwxr-x 7 root root 200 7月 25 22:05 .git -rw-rw-r-- 1 root root 11 7月 25 22:04 README.md
八、提交 README.md 到仓库
[root@arslinux-01 studygit]# git add README.md [root@arslinux-01 studygit]# git commit -m "first commit" [master(根提交) f6afa16] first commit 1 file changed, 1 insertion(+) create mode 100644 README.md
九、将仓库内容推到远程
[root@arslinux-01 studygit]# git remote add origin https://github.com/axxxxx4xxx/studygit.git
十、将更改推送到远程
[root@arslinux-01 studygit]# git push -u origin master Username for 'https://github.com': axxxxx4xxx Password for 'https://axxxxx4xxx@github.com': Counting objects: 3, done. Writing objects: 100% (3/3), 220 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/axxxxx4xxx/studygit.git * [new branch] master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master。
十一、推送新增文件操做
[root@arslinux-01 studygit]# echo "73737372hhdjdjd" > 2.txt [root@arslinux-01 studygit]# ls 2.txt README.md [root@arslinux-01 studygit]# git add 2.txt [root@arslinux-01 studygit]# git commit -m "add 2.txt" [master 6e4549c] add 2.txt 1 file changed, 1 insertion(+) create mode 100644 2.txt [root@arslinux-01 studygit]# git push warning: push.default 未设置,它的默认值将会在 Git 2.0 由 'matching' 修改成 'simple'。若要再也不显示本信息并在其默认值改变后维持当前使用习惯, 进行以下设置: git config --global push.default matching 若要再也不显示本信息并从如今开始采用新的使用习惯,设置: git config --global push.default simple 参见 'git help config' 并查找 'push.default' 以获取更多信息。 ('simple' 模式由 Git 1.7.11 版本引入。若是您有时要使用老版本的 Git, 为保持兼容,请用 'current' 代替 'simple' 模式) Username for 'https://github.com': arsenal4life Password for 'https://arsenal4life@github.com': Counting objects: 4, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 281 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/arsenal4life/studygit.git f6afa16..6e4549c master -> master
十二、根据提示,设置一下 git config
[root@arslinux-01 studygit]# git config --global push.default simple
1三、网页刷新,就能够看到新增的文件
22.8 克隆远程仓库
一、网页端仓库中,点右侧绿色“Clone or download”,复制生成的 git 连接
二、克隆到本机
[root@arslinux-01 studygit]# cd [root@arslinux-01 ~]# cd /home/ [root@arslinux-01 home]# git clone https://github.com/arsenal4life/studygit.git 正克隆到 'studygit'... remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0 Unpacking objects: 100% (6/6), done. [root@arslinux-01 home]# cd studygit/ [root@arslinux-01 studygit]# ls 2.txt README.md
三、更改 README.md 内容,并推送到远程
[root@arslinux-01 studygit]# echo "hello hello" >> README.md [root@arslinux-01 studygit]# echo "bye" >> README.md [root@arslinux-01 studygit]# git add README.md [root@arslinux-01 studygit]# git commit -m "change README.md" [master b2c0aa1] change README.md 1 file changed, 2 insertions(+) [root@arslinux-01 studygit]# git push Username for 'https://github.com': arsenal4life Password for 'https://arsenal4life@github.com': Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 304 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/arsenal4life/studygit.git 6e4549c..b2c0aa1 master -> master
四、成功
五、将远程更改文件同步到本地
——远程修改 2.txt 内容
[root@arslinux-01 studygit]# git pull remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. 来自 https://github.com/arsenal4life/studygit b2c0aa1..cce2494 master -> origin/master 更新 b2c0aa1..cce2494 Fast-forward 2.txt | 3 +++ 1 file changed, 3 insertions(+) [root@arslinux-01 studygit]# cat 2.txt 73737372hhdjdjd thank you go go go ore wa neko ga suki
22.9 分支管理
22.9 分支管理
git branch 查看分支
git branch 分支名 建立分支
git checkout 分支名 切换分支
[root@arslinux-01 gitroot]# git branch * master [root@arslinux-01 gitroot]# git branch arslinux [root@arslinux-01 gitroot]# git branch arslinux * master [root@arslinux-01 gitroot]# git checkout arslinux 切换到分支 'arslinux' [root@arslinux-01 gitroot]# git branch * arslinux master
——当前使用的分支前面会有一个 * 在 arslinux 分支下
——编辑 2.txt,并提交到新分支
[root@arslinux-01 gitroot]# echo "kajlhlk" > 2.txt [root@arslinux-01 gitroot]# git add 2.txt [root@arslinux-01 gitroot]# git commit -m "add 2.txt" [arslinux 0f6b36c] add 2.txt 1 file changed, 1 insertion(+) create mode 100644 2.txt [root@arslinux-01 gitroot]# ls 1.txt 2.txt [root@arslinux-01 gitroot]# git checkout master 切换到分支 'master' [root@arslinux-01 gitroot]# ls 1.txt
分支能够隔离开文件
git merge 分支名 合并分支
[root@arslinux-01 gitroot]# git merge arslinux 更新 3517c53..0f6b36c Fast-forward 2.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 2.txt [root@arslinux-01 gitroot]# ls 1.txt 2.txt
想要将文件合并到哪一个分支下,那么在合并前,须要先切换到该分支下,再进行合并分支操做
以上操做中,合并分以后,master 分支下有了 2.txt
——合并分支时,若是合并的分支下有相同文件名的文件,那么文件内容须要一致
[root@arslinux-01 gitroot]# echo "12sddsf2232" > 2.txt [root@arslinux-01 gitroot]# git add 2.txt [root@arslinux-01 gitroot]# git commit -m "ch 2.txt" [master bb88c13] ch 2.txt 1 file changed, 1 insertion(+), 1 deletion(-) [root@arslinux-01 gitroot]# git checkout arslinux 切换到分支 'arslinux' [root@arslinux-01 gitroot]# vim 2.txt [root@arslinux-01 gitroot]# git add 2.txt [root@arslinux-01 gitroot]# git commit -m "ch 2.txt" [arslinux 79c2a72] ch 2.txt 1 file changed, 1 deletion(-) [root@arslinux-01 gitroot]# git checkout master 切换到分支 'master' [root@arslinux-01 gitroot]# git merge arslinux 自动合并 2.txt 冲突(内容):合并冲突于 2.txt 自动合并失败,修正冲忽然后提交修正的结果。 [root@arslinux-01 gitroot]# vim 2.txt [root@arslinux-01 gitroot]# cat 2.txt <<<<<<< HEAD 12sddsf2232 ======= >>>>>>> arslinux
若是master分支和aming分支都对2.txt进行了编辑,当合并时会提示冲突,须要先解决冲突才能够继续合并。
解决冲突的方法是在master分支下,编辑2.txt,改成aming分支里面2.txt的内容。 而后提交2.txt,再合并aming分支。
可是这样有一个问题,万一master分支更改的内容是咱们想要的呢? 能够编辑2.txt内容,改成想要的,而后提交。切换到aming分支,而后合并master分支到aming分支便可(倒着合并)。合并分支有一个原则,那就是要把最新的分支合并到旧的分支。也就是说merge后面跟的分支名字必定是最新的分支。
git branch -d 分支名 删除分支
git branch -D arslinux 强制删除分支
[root@arslinux-01 gitroot]# git branch -d arslinux 已删除分支 arslinux(曾为 fcb0316)。
若是分支没有合并,删除以前会提示,那就不合并,强制删除
22.10 远程分支管理
使用分支的原则:
master 分支很是重要,线上发布代码用这个分支,平时咱们开发代码不要在这个分支上。
建立一个 dev 分支,专门用做开发,当发布到线上以前,才会把 dev 分支合并到 master
开发人员应该在 dev 的基础上再分支成我的分支,我的分支(在本身pc上)里面开发代码,而后合并到 dev 分支
dev分支合并bob分支的命令是:
git checkout dev //先切换到dev分支,而后
git merge bob
远程分支:
git ls-remote origin 查看远程分支
[root@arslinux-01 tmp]# git clone https://github.com/axxxxxx4xxxx/studygit.git 正克隆到 'studygit'... remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (11/11), done. remote: Total 15 (delta 0), reused 12 (delta 0), pack-reused 0 Unpacking objects: 100% (15/15), done. [root@arslinux-01 tmp]# cd studygit/ [root@arslinux-01 studygit]# git branch * master [root@arslinux-01 studygit]# git ls-remote origin 38e08903596878b892452d53aa96dda7b76a7c64HEAD 38e08903596878b892452d53aa96dda7b76a7c64refs/heads/dev 38e08903596878b892452d53aa96dda7b76a7c64refs/heads/master
——本地新建的分支若是不推送到远程,对其余人就是不可见的
——git clone 的时候默认只把 master 分支克隆下来,若是想把全部分支都克隆下来,须要手动建立,在本地建立和远程分支对应的分支,使用 git checkout -b 分支名 origin/分支名,本地和远程分支的名称要一致
git checkout -b 分支名 origin/分支名 本地建立和远程分支对应的分支
[root@arslinux-01 studygit]# git checkout -b dev origin/dev 分支 dev 设置为跟踪来自 origin 的远程分支 dev。 切换到一个新分支 'dev' [root@arslinux-01 studygit]# git branch * dev master
——对于 git push 分支分两种状况:
1)当本地分支和远程分支一致时
git push 会把全部本地分支的变动一同推送到远程,若是想只推送一个分支,使用 git push origin 分支名
2)当本地分支比远程分支多
默认 git push 只推送本地和远程一致的分支,想要把多出来的本地分支推送到远程时,使用 git push origin 分支名 若是推送失败,先用 git pull 抓取远程的新提交
一致:
[root@arslinux-01 studygit]# echo "ssssssss">2.txt [root@arslinux-01 studygit]# echo "bbbbbbbb">>2.txt [root@arslinux-01 studygit]# cat 2.txt ssssssss bbbbbbbb [root@arslinux-01 studygit]# git add 2.txt [root@arslinux-01 studygit]# git commit -m "add 2.txt" [dev e7340f2] add 2.txt 1 file changed, 2 insertions(+), 5 deletions(-) [root@arslinux-01 studygit]# git push origin dev Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/axxxxx4xxxx/studygit.git 38e0890..e7340f2 dev -> dev
不一致:
[root@arslinux-01 studygit]# git branch dev2 [root@arslinux-01 studygit]# git checkout dev2 切换到分支 'dev2' [root@arslinux-01 studygit]# echo "aaaaaaaaa" > 3.txt [root@arslinux-01 studygit]# git add 3.txt [root@arslinux-01 studygit]# git commit -m "add 3.txt" [dev2 bdf6b7d] add 3.txt 1 file changed, 1 insertion(+) create mode 100644 3.txt [root@arslinux-01 studygit]# git push origin dev2 Counting objects: 4, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 298 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/xxxxxxx4xxxx/studygit.git e7340f2..bdf6b7d dev2 -> dev2
22.11 标签管理
——标签相似于快照功能,能够给版本库打一个标签,记录某个时刻库的状态,也能够随时恢复到该状态
git tag v1.0 给master打一个标签v1.0
git tag 能够查看全部的标签
git show v1.0 查看标签信息
[root@arslinux-01 studygit]# git checkout master 切换到分支 'master' [root@arslinux-01 studygit]# git tag v1.0 [root@arslinux-01 studygit]# git tag v1.0 [root@arslinux-01 studygit]# git show v1.0 commit 38e08903596878b892452d53aa96dda7b76a7c64 Author: arslinux <zyxxxxxxxx@qq.com> Date: Thu Jul 25 22:37:14 2019 +0800 change2 2.txt diff --git a/2.txt b/2.txt index 77d3d2a..07ced64 100644 --- a/2.txt +++ b/2.txt @@ -1,4 +1,5 @@ 73737372hhdjdjd thank you go go go +dlj;adkjf;adfas ore wa neko ga suki
——tag 是针对 commit 来打标签的,因此能够针对历史的 commit 来打 tag
git log --pretty=oneline 查看历史 commit
git log --pretty=oneline --abbrev-commit 查看历史 commit,用简写 commit
git tag v版本号 commit值 针对历史 commit 打标签
git tag -a v版本号 -m "描述" commit值 对标签进行描述
git tag -d v版本号 删除标签
git push origin v版本号 推送指定标签到远程
git push --tag v版本号 推送全部标签到远程
git tag v版本号 -d 删除本地标签
git push origin:refs/tags/v版本号 删除远程标签
[root@arslinux-01 studygit]# git log --pretty=oneline 38e08903596878b892452d53aa96dda7b76a7c64 change2 2.txt cce24941a0e74d9c94cd05f1a59e6993ac54ca01 Update 2.txt b2c0aa1d1b2749eeb0958ca772c378790651dd0f change README.md 6e4549cbe9f7d415eb219018b3fbbfc2e1e42c98 add 2.txt f6afa16c437cf2917d220aace0e01963575b7383 first commit [root@arslinux-01 studygit]# git log --pretty=oneline --abbrev-commit 38e0890 change2 2.txt cce2494 Update 2.txt b2c0aa1 change README.md 6e4549c add 2.txt f6afa16 first commit
[root@arslinux-01 studygit]# git tag v0.8 6e4549cbe9f7d [root@arslinux-01 studygit]# git tag v0.8 v1.0
[root@arslinux-01 studygit]# git tag -a v0.1 -m "first tag" f6afa16c4 [root@arslinux-01 studygit]# git show v0.1 tag v0.1 Tagger: arslinux <zxxxxxx@qq.com> Date: Sat Jul 27 22:18:25 2019 +0800 first tag commit f6afa16c437cf2917d220aace0e01963575b7383 Author: arslinux <zxxxxxxxxx@qq.com> Date: Thu Jul 25 22:07:51 2019 +0800 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb8db93 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# studygit
[root@arslinux-01 studygit]# git tag -d v0.1 已删除 tag 'v0.1'(曾为 7db3981)
[root@arslinux-01 studygit]# git push origin v1.0 Total 0 (delta 0), reused 0 (delta 0) To https://github.com/arsenal4life/studygit.git * [new tag] v1.0 -> v1.0 [root@arslinux-01 studygit]# git push --tag origin Total 0 (delta 0), reused 0 (delta 0) To https://github.com/arsenal4life/studygit.git * [new tag] v0.8 -> v0.8
[root@arslinux-01 studygit]# git tag v0.8 -d 已删除 tag 'v0.8'(曾为 6e4549c) [root@arslinux-01 studygit]# git tag v1.0
[root@arslinux-01 studygit]# git push origin :refs/tags/v0.8 Username for 'https://github.com': arsenal4life Password for 'https://arsenal4life@github.com': To https://github.com/arsenal4life/studygit.git - [deleted] v0.8
22.12 git别名
git config --global alias.别名 命令 设置别名
git config --list 查看全部配置
git config --list |grep alias 查看别名
git config --global --unset alias.别名 取消别名
[root@arslinux-01 studygit]# git config --global alias.ci commit [root@arslinux-01 studygit]# echo "dafafa" >4.txt [root@arslinux-01 studygit]# git add 4.txt [root@arslinux-01 studygit]# git ci -m "add 4.txt" [master 993ce4b] add 4.txt 1 file changed, 1 insertion(+) create mode 100644 4.txt [root@arslinux-01 studygit]# git config --global alias.br branch [root@arslinux-01 studygit]# git br dev dev2 * master [root@arslinux-01 studygit]# git config --global alias.co checkout [root@arslinux-01 studygit]# git co dev 切换到分支 'dev'
[root@arslinux-01 studygit]# git config --list user.email=zxxxxxxxx@qq.com user.name=arslinux push.default=simple alias.ci=commit alias.br=branch alias.co=checkout core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true remote.origin.url=https://github.com/axxxxxxxxxxx/studygit.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master branch.dev.remote=origin branch.dev.merge=refs/heads/dev
[root@arslinux-01 studygit]# git config --list|grep alias alias.ci=commit alias.br=branch alias.co=checkout
[root@arslinux-01 studygit]# git config --global --unset alias.br [root@arslinux-01 studygit]# git br git:'br' 不是一个 git 命令。参见 'git --help'。 您指的是这其中的某一个么? branch var
——git config 的配置能够在 /root/.gitconfig 中定义
查询 log 小技巧:(颜色区分显示)
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
22.13 搭建git服务器
——github 毕竟是公开的,而私有仓库又得花钱买。因此咱们能够想办法搭建一个私有的,只本身公司使用的。Gitlab 是个不错的选择。
一、安装 git,arslinux-02 作为服务端
[root@arslinux-02 ~]# yum install -y git
二、添加 git 用户,并设置 shell 为 /usr/bin/git-shell,目的是为了避免让 git 用户远程登录
[root@arslinux-02 ~]# useradd -s /usr/bin/git-shell git
三、建立 authorized_keys 文件,并更改属主、属组和权限,用来存客户端机器上的公钥
[root@arslinux-02 ~]# cd /home/git/ [root@arslinux-02 git]# mkdir .ssh [root@arslinux-02 git]# touch .ssh/authorized_keys [root@arslinux-02 git]# chmod 600 .ssh/authorized_keys [root@arslinux-02 git]# chown -R git:git .ssh
四、将公钥添加到服务端 authorized_keys 文件中,并在客户端尝试链接
[root@arslinux-02 git]# vim .ssh/authorized_keys [root@arslinux-01 ~]# ssh git@192.168.194.132 fatal: Interactive git shell is not enabled. hint: ~/git-shell-commands should exist and have read and execute access. Connection to 192.168.194.132 closed.
五、服务端建立 git 仓库,建立裸仓库
[root@arslinux-02 git]# cd /data/ [root@arslinux-02 data]# mkdir /data/gitroot [root@arslinux-02 data]# cd /data/gitroot/ [root@arslinux-02 gitroot]# git init --bare sample.git 初始化空的 Git 版本库于 /data/gitroot/sample.git/ [root@arslinux-02 gitroot]# ls sample.git [root@arslinux-02 gitroot]# chown -R git:git sample.git/
——git init --bare sample.git // 会建立一个裸仓库,裸仓库没有工做区,由于服务器上的 Git 仓库纯粹是为了共享,因此不让用户直接登陆到服务器上去改工做区,而且服务器上的Git仓库一般都以.git结尾
——以上操做是在 git 服务器上作的,平时 git 服务器是不须要开发人员登陆修改代码的,它仅仅是充当着一个服务器的角色,就像 github 同样,平时操做都是在咱们本身的pc上作的
六、客户端上克隆远程仓库
[root@arslinux-01 ~]# git clone git@192.168.194.132:/data/gitroot/sample.git 正克隆到 'sample'... warning: 您彷佛克隆了一个空版本库。 [root@arslinux-01 ~]# cd sample/ [root@arslinux-01 sample]# ll -a 总用量 4 drwxrwxr-x 3 root root 18 7月 28 12:19 . dr-xr-x---. 10 root root 4096 7月 28 12:19 .. drwxrwxr-x 7 root root 119 7月 28 12:19 .git
七、建立新文件到仓库,推送到远程
[root@arslinux-01 sample]# cp /etc/init.d/mysqld . [root@arslinux-01 sample]# git add mysqld [root@arslinux-01 sample]# git commit -m "add mysqld" [master(根提交) 7f37e19] add mysqld 1 file changed, 378 insertions(+) create mode 100755 mysqld [root@arslinux-01 sample]# git push Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 3.84 KiB | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.194.132:/data/gitroot/sample.git * [new branch] master -> master
若是 git push 提示没有分支,可使用 git push origin master 来操做,会在裸仓库建立新分支
八、再推送新文件就不会提示了
[root@arslinux-01 sample]# echo "dafasdfasdf" >222.txt [root@arslinux-01 sample]# git add 222.txt [root@arslinux-01 sample]# git commit -m "add 222.txt" [master a9de871] add 222.txt 1 file changed, 1 insertion(+) create mode 100644 222.txt [root@arslinux-01 sample]# git push Counting objects: 4, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.194.132:/data/gitroot/sample.git 7f37e19..a9de871 master -> master
九、不妨到 /tmp/ 目录下,克隆服务端的 sample.git,能够看到,客户端新建文件已经推到服务端了
[root@arslinux-01 sample]# cd /tmp/ [root@arslinux-01 tmp]# git clone git@192.168.194.132:/data/gitroot/sample.git 正克隆到 'sample'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 0), reused 0 (delta 0) 接收对象中: 100% (6/6), 4.09 KiB | 0 bytes/s, done. [root@arslinux-01 tmp]# cd sample/ [root@arslinux-01 sample]# ls 222.txt mysqld
十、若是有多个服务器链接 git 服务端,并且其余服务器对服务端作了更改,那么客户端能够 git pull 来更新仓库(/tmp/sample/ 和 /data/sample/ 就当作两个服务器)
[root@arslinux-01 tmp]# cd sample/ [root@arslinux-01 sample]# ls 222.txt mysqld [root@arslinux-01 sample]# echo "435678" >> 222.txt [root@arslinux-01 sample]# git add 222.txt [root@arslinux-01 sample]# git commit -m "ch 222.txt" [master 4e5ad08] ch 222.txt 1 file changed, 1 insertion(+) [root@arslinux-01 sample]# git push Counting objects: 5, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 289 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.194.132:/data/gitroot/sample.git a9de871..4e5ad08 master -> master
[root@arslinux-01 sample]# cd [root@arslinux-01 ~]# cd sample/ [root@arslinux-01 sample]# ls 222.txt mysqld [root@arslinux-01 sample]# git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. 来自 192.168.194.132:/data/gitroot/sample a9de871..4e5ad08 master -> origin/master 更新 a9de871..4e5ad08 Fast-forward 222.txt | 1 + 1 file changed, 1 insertion(+) [root@arslinux-01 sample]# cat 222.txt dafasdfasdf 435678
这样就能够很是方便协同操做
22.14/22.15 安装gitlab
gitlab 官网 https://about.gitlab.com/gitlab-com/
官方安装文档:https://about.gitlab.com/install/#centos-7
要求服务器内存很多于2g,不然会卡死
一、建立 gitlab 的安装源
[root@arslinux-01 ~]# vim /etc/yum.repos.d/gitlab.repo [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gpgcheck=0 enabled=1
二、安装 gitlab
[root@arslinux-01 ~]# yum install -y gitlab-ce
三、自动配置 gitlab
[root@arslinux-01 ~]# gitlab-ctl reconfigure [root@arslinux-01 ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.194.130:27017 0.0.0.0:* LISTEN 7504/mongod tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 7504/mongod tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 14204/node_exporter tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 14189/gitlab-workho tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 14222/puma 3.12.0 ( tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 12872/unicorn maste tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12951/nginx: master tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 7332/rpc.mountd tcp 0 0 0.0.0.0:37361 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 12888/sidekiq 5.2.7 tcp 0 0 127.0.0.1:9236 0.0.0.0:* LISTEN 14209/gitaly tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7242/sshd tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 15042/grafana-serve tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7675/master tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 12951/nginx: master tcp 0 0 0.0.0.0:35038 0.0.0.0:* LISTEN 7265/rpc.statd tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 14233/redis_exporte tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 14240/prometheus tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 7256/zabbix_agentd tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 14284/postgres_expo tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 7330/zabbix_server tcp 0 0 127.0.0.1:9093 0.0.0.0:* LISTEN 14275/alertmanager tcp6 0 0 :::3306 :::* LISTEN 7579/mysqld tcp6 0 0 :::33836 :::* LISTEN - tcp6 0 0 :::53101 :::* LISTEN 7265/rpc.statd tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 ::1:9168 :::* LISTEN 14222/puma 3.12.0 ( tcp6 0 0 :::20048 :::* LISTEN 7332/rpc.mountd tcp6 0 0 :::22 :::* LISTEN 7242/sshd tcp6 0 0 ::1:25 :::* LISTEN 7675/master tcp6 0 0 :::2049 :::* LISTEN - tcp6 0 0 :::10050 :::* LISTEN 7256/zabbix_agentd tcp6 0 0 :::10051 :::* LISTEN 7330/zabbix_server tcp6 0 0 :::10052 :::* LISTEN 7264/java tcp6 0 0 :::9094 :::* LISTEN 14275/alertmanager
四、关闭 gitlab,能够看到 gitlab 相关服务
[root@arslinux-01 ~]# gitlab-ctl stop ok: down: alertmanager: 0s, normally up ok: down: gitaly: 0s, normally up ok: down: gitlab-monitor: 0s, normally up ok: down: gitlab-workhorse: 1s, normally up ok: down: grafana: 0s, normally up ok: down: logrotate: 1s, normally up ok: down: nginx: 0s, normally up ok: down: node-exporter: 0s, normally up ok: down: postgres-exporter: 1s, normally up ok: down: postgresql: 0s, normally up ok: down: prometheus: 1s, normally up ok: down: redis: 0s, normally up ok: down: redis-exporter: 1s, normally up ok: down: sidekiq: 0s, normally up ok: down: unicorn: 1s, normally up
五、中止本地以前安装的 nginx 服务,redis-server
[root@arslinux-01 ~]# /etc/init.d/nginx stop Stopping nginx (via systemctl): [ 肯定 ] [root@arslinux-01 ~]# chkconfig nginx off [root@arslinux-01 ~]# killall redis-server
六、启动 gitlab(gitlab-ctl stop/restart/start/status)
[root@arslinux-01 ~]# gitlab-ctl start ok: run: alertmanager: (pid 15894) 1s ok: run: gitaly: (pid 15905) 0s ok: run: gitlab-monitor: (pid 15923) 1s ok: run: gitlab-workhorse: (pid 15925) 0s ok: run: grafana: (pid 15932) 1s ok: run: logrotate: (pid 15938) 0s ok: run: nginx: (pid 15946) 1s ok: run: node-exporter: (pid 15951) 0s ok: run: postgres-exporter: (pid 15955) 1s ok: run: postgresql: (pid 15960) 0s ok: run: prometheus: (pid 15962) 1s ok: run: redis: (pid 15976) 0s ok: run: redis-exporter: (pid 15981) 1s ok: run: sidekiq: (pid 15986) 0s ok: run: unicorn: (pid 15992) 0s
七、网页访问 gitlab,只要输入 ip 地址便可
若是出现 502 错误,那么请检查内存是否太小,通常不小于 4G
八、修改密码后,登陆,默认用户名 root,密码就是刚刚修改的
登陆后就能够建立项目
22.16 使用gitlab
gitlab经常使用命令:https://www.cnyunwei.cc/archives/1204
进入 gitlab,先建立组,再建立项目
一、建立组:
二、建立项目:
和 github 同样,须要添加 ssh key,才能够和 gitlab 通讯
三、设置 ssh key
右上角头像——setting——SSH Keys
四、建立用户
顶部中间扳手图标(Admin Area)——New user
五、进入用户编辑,能够设定用户密码
六、退出,用新建的用户名密码登陆,首次登陆须要修改密码,能够设成和原来同样的密码,而后就能够建立项目了
22.17 gitlab备份和恢复
——gitlab 备份
[root@arslinux-01 ~]# gitlab-rake gitlab:backup:create
——备份的文件默认会放到 /var/opt/gitlab/backups/ 下
[root@arslinux-01 ~]# ls /var/opt/gitlab/backups/ 1564299157_2019_07_28_12.1.1_gitlab_backup.tar [root@arslinux-01 ~]# du -sh /var/opt/gitlab/backups/1564299157_2019_07_28_12.1.1_gitlab_backup.tar 132K/var/opt/gitlab/backups/1564299157_2019_07_28_12.1.1_gitlab_backup.tar
——gitlab 恢复
1)暂停 unicorn、sidekiq 服务
[root@arslinux-01 ~]# gitlab-ctl stop unicorn ; gitlab-ctl stop sidekiq
2)恢复 gitlab-rake gitlab:backup:restore BACKUP=xxxxx (这里是一个编号,即备份文件的前缀)
[root@arslinux-01 ~]# gitlab-rake gitlab:backup:restore BACKUP=1564299157_2019_07_28_12.1.1
——再启动服务 gitlab-ctl start