Gitlab deployment and application

Gitlab deployment and application
[root @ localhost ~] # mkdir XGP
[root @ localhost ~] # cd XGP /
[root @ localhost XGP] # git the init
initialize an empty Git repository in /root/xgp/.git/
[root @ localhost XGP] # xgp.txt vim
[root @ localhost XGP] # CAT xgp.txt
111master
[root @ localhost XGP] # git the Add xgp.txt
[root @ localhost XGP] # git the commit "the first submission from the master branch" -m
[master (root Submit) b211b8e] submission of a branch from the master
. 1 File changed, Insertion. 1 (+)
Create MODE 100644 xgp.txt

First, we create a dev branch, and then switch to the dev branch:
[root @ localhost XGP] # git Checkout -b dev
switch to a new branch 'dev'

Gitlab deployment and application
git checkout command with the -b parameter indicates the switching and corresponds to the following two commands:
$ Git Branch dev
$ git checkout dev
Switched to Branch 'dev'

Then, view the current branch with git branch command:
[root @ localhost XGP] # git branch

  • dev
    Master
    Gitlab deployment and application

git branch command lists all the branches, ahead of the current branch monogram an asterisk.

Then, we can properly filed on dev branch, such as for xgp.txt be modified, add a line:
[root @ localhost XGP] # CAT xgp.txt
111master
Qqqqdve added

Then submit:
[root @ localhost XGP] # git the Add xgp.txt
[root @ localhost XGP] # git the commit -m "First dev"
[dev eac3426] first dev
1 File changed, 1 Insertion (+)

Now, dev branch of the work is completed, we can switch back to the master branch:
[root @ localhost XGP] # git Checkout master
switch to branch 'master'
Gitlab deployment and application
after switching back to the master branch, and then view a xgp.txt file, just add content gone! Because that is submitted on the dev branch, and submit the master branch point has not changed at the moment:
[root @ localhost XGP] # CAT xgp.txt
111master

Now, we have consolidated the results of the work of the dev branch to master branch:
[root @ localhost XGP] # git Merge dev
update b211b8e..eac3426
Fast-Forward
xgp.txt | 1 +
1 File changed, 1 Insertion (+)
git Merge command is used to specify the branch to merge the current branch. After the merger, and then view the contents of xgp.txt, you can see the latest and submit dev branch is exactly the same.
Fast-forward took note of the above information, Git tells us that this merger is a "fast-forward mode," which is pointing directly to master the current dev submitted, so the merger is very fast.
Of course, not every merger can Fast-forward, we will talk about later combined with other methods.
After the merger is completed, you can safely delete the dev branch:

Look at
[root @ localhost XGP] # git log
the commit eac342633a72b3590a019e4d758f4a60707acda2
Author: ADMIN <ADMIN ADMIN @>
a Date: Thu 14 Nov 2019 09:18:47 +0800

第一次dev

commit b211b8ef636e987166fb4a056fb778020f6518ae
Author: admin <admin@admin>
Date: Thu Nov 14 09:12:11 2019 +0800

第一次提交从master分支

Delete dev branch
[root @ localhost xgp] # git branch -d dev
deleted branches dev (who eac3426).

After delete, view branch, the master branch on the left:
[root @ localhost XGP] # git Branch

  • master

Because creating, deleting and merging branches very quickly, so you are encouraged to use Git branch to complete a task, and then delete the merged branch, and this is directly in the master
branch work effect is the same, but the process more secure.
Summary
Git encourage extensive use of branches:
View branch: git branch
create a branch: git branch <name>
switch branch: git checkout <name>
Create a + switching branch: git checkout -b <name>
merge a branch to the current branch: git merge < name>
delete branch: git branch -d <name>

Resolve conflicts
unhappy things in life all likelihood, merging branches often is not easy.
Prepare the new xgp branch, continue the development of our new branch:
[root @ localhost xgp] # git Checkout xgp -b
switch to a new branch 'xgp'
modify xgp.txt last line read:
[root @ localhost xgp] # xgp.txt CAT
111master
qqqqdve
conflict added
on xgp branch submitted:
[root @ localhost xgp] # git the Add xgp.txt
[root @ localhost xgp] # git the commit -m "xgp conflict"
[xgp 9a92c8f] xgp conflict
1 file changed , 1 insertion (+)

Switch to the master branch:
[XGP the root @ localhost] # Git Checkout master
switch to branch 'master'
[XGP the root @ localhost] # CAT xgp.txt
111master
Qqqqdve

In the last line on the master branch xgp.txt file instead:
[root @ localhost XGP] # CAT xgp.txt
111master
qqqqdve
add bug conflict

Submitted:
[root @ localhost XGP] # git the Add xgp.txt
[root @ localhost XGP] # git the commit -m "1 to submit the conflict"
[Master 43f4ad7] 1 submission conflict
1 file changed, 1 insertion (+ )

Now, master branch and xgp each branch are respectively a new submission, it becomes this:
Gitlab deployment and application
In this case, Git can not perform "quick merger" can only try to merge their modifications, but such a merger could be there is a conflict, we try:
[root @ localhost XGP] # git XGP merge
to automatically merge xgp.txt
conflict (content): merge conflict in xgp.txt
failed automatic merge, revise and submit the corrected results conflict.

Sure enough, the conflict! Git tells us that there is a conflict xgp.txt files, you must manually resolve the conflict before submitting. git status can also tell us conflicting files:
[root @ localhost XGP] # git status

Located at the branch master

You have not yet merged path.

(Resolve conflicts and run "git commit")

#

Unmerged path:

(Use "git add <file> ..." tag solution)

#

The parties amended: xgp.txt

#
Modify added yet submitted (using the "git add" and / or "git commit -a")

我们可以直接查看 xgp.txt 的内容:
[root@localhost xgp]# cat xgp.txt
111master
qqqqdve
<<<<<<< HEAD #删除
bug冲突
======= #删除
冲突
-----------xgp #删除

再提交:
[root@localhost xgp]# vim xgp.txt
[root@localhost xgp]# git add xgp.txt
[root@localhost xgp]# git commit -m "解决冲突"
[master 8a29ce6] 解决冲突

现在, master 分支和xgp分支变成了下图所示:

Gitlab deployment and application

用带参数的 git log 也可以看到分支的合并情况
[root@localhost xgp]# git log --graph --pretty=oneline --abbrev-commit

  • 8a29ce6 解决冲突
    |\
    | * 9a92c8f xgp 冲突
  • | 43f4ad7 1 提交 冲突
    |/
  • eac3426 第一次dev
  • b211b8e 第一次提交从master分支

[root@localhost xgp]# cat xgp.txt
111master
qqqqdve
bug冲突
冲突

最后,删除 xgp 分支:
[root@localhost xgp]# git branch -d xgp
已删除分支 xgp(曾为 9a92c8f)。

工作完成。
小结
当 Git 无法自动合并分支时,就必须首先解决冲突。解决冲突后,再提交,合并完成。
用 git log --graph 命令可以看到分支合并图。

分支管理策略
通常,合并分支时,如果可能, Git 会用 Fast forward 模式,但这种模式下,删除分支后,会丢掉分支信息。如果要强制禁用 Fast forward 模式, Git 就会在 merge 时生成一个新的 commit,这样,从分支历史上就可以看出分
支信息。
下面我们实战一下--no-ff 方式的 git merge:
首先,仍然创建并切换 dev 分支:
[root@localhost xgp]# git checkout -b dev
切换到一个新分支 'dev'

修改 readme.txt 文件,并提交一个新的 commit:
[root@localhost xgp]# cat xgp.txt
111master
qqqqdve
bug冲突
冲突
强制禁用 Fast forward #添加

[root@localhost xgp]# git add xgp.txt # 提交到缓存
[root@localhost xgp]# git commit -m "强制禁用 Fast forward " #提交到版本库
[dev ea40f66] 强制禁用 Fast forward
1 file changed, 1 insertion(+)

现在,我们切换回 master:
[root@localhost xgp]# git checkout master
切换到分支 'master'

准备合并 dev 分支,请注意--no-ff 参数,表示禁用 Fast forward:
[root@localhost xgp]# git merge --no-ff -m "merge with no-ff" dev
Merge made by the 'recursive' strategy.
xgp.txt | 1 +
1 file changed, 1 insertion(+)

因为本次合并要创建一个新的 commit,所以加上-m 参数,把 commit 描述写进去。
合并后,我们用 git log 看看分支历史:
[root@localhost xgp]# git log --graph --pretty=oneline --abbrev-commit

  • 50623ba merge with no-ff
    |\
    | * ea40f66 强制禁用 Fast forward
    |/
  • 8a29ce6 解决冲突
    |\
    | * 9a92c8f xgp 冲突
  • | 43f4ad7 1 提交 冲突
    |/
  • eac3426 第一次dev
  • b211b8e 第一次提交从master分支
    可以看到,不使用 Fast forward 模式, merge 后就像这样:
    Gitlab deployment and application

Bug 分支
软件开发中, bug 就像家常便饭一样。有了 bug 就需要修复,在 Git 中,由于分支是如此的强大,所以,每个 bug都可以通过一个新的临时分支来修复,修复后,合并分支,然后将临时分支删除。当你接到一个修复一个代号 101 的 bug 的任务时,很自然地,你想创建一个分支 issue-101 来修复它,但是,等等,当前正在 dev 上进行的工作还没有提交:

并不是你不想提交,而是工作只进行到一半,还没法提交,预计完成还需 1 天时间。但是,必须在两个小时内修复该
bug,怎么办?
幸好, Git 还提供了一个 stash 功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作:

制作一个测试文件
[root@localhost xgp]# vim xgp.txt
[root@localhost xgp]# cat xgp.txt
111master
qqqqdve
bug冲突
冲突
强制禁用 Fast forward
测试存储区 #添加
[root@localhost xgp]# vim xxx.txt
[root@localhost xgp]# git add xgp.txt xxx.txt
[root@localhost xgp]# git status
位于分支 dev
要提交的变更:
(使用 "git reset HEAD <file>..." 撤出暂存区)

修改: xgp.txt

未跟踪的文件:
(使用 "git add <file>..." 以包含要提交的内容)

xxx.txt 

[root@localhost xgp]# git stash
Saved working directory and index state WIP on dev: ea40f66 强制禁用 Fast forward HEAD 现在位于 ea40f66强制禁用 Fast forward
[root@localhost xgp]# git status

位于分支 master

无文件要提交,干净的工作区

现在,用 git status 查看工作区,就是干净的(除非有没有被 Git 管理的文件),因此可以放心地创建分支来修复bug。
首先确定要在哪个分支上修复 bug,假定需要在 master 分支上修复,就从 master 创建临时分支:
[root@localhost xgp]# git checkout dev
切换到分支 'dev'
现在修复 bug,需要把“Git is free software ...”改为“Git is a free software ...”, 然后用 git stash pop,恢复的同时把 stash 内容也删了:
先查看一下
[root@localhost xgp]# git stash list
stash@{0}: WIP on master: 88eeb08 提交
[root@localhost xgp]# git stash show
xgp.txt | 1 +
xxx.txt | 1 +
2 files changed, 2 insertions(+)
恢复
[root@localhost xgp]# git stash pop
位于分支 dev
要提交的变更:
(使用 "git reset HEAD <file>..." 撤出暂存区)

新文件:    xxx.txt

尚未暂存以备提交的变更:
(使用 "git add <file>..." 更新要提交的内容)
(使用 "git checkout -- <file>..." 丢弃工作区的改动)

修改:      xgp.txt

丢弃了 refs/stash@{0} (f5b7fdc796da9978e268083f6985ed5ba28ec373)

[root@localhost xgp]# git status
位于分支 dev
要提交的变更:
(使用 "git reset HEAD <file>..." 撤出暂存区)

新文件:    xxx.txt

尚未暂存以备提交的变更:
(使用 "git add <file>..." 更新要提交的内容)
(使用 "git checkout -- <file>..." 丢弃工作区的改动)

修改: xgp.txt

[root@localhost xgp]# git commit -m "测试存储区 master提交暂存区 devtij交版本"
[dev 1256166] 测试存储区 master提交暂存区 devtij交版本
1 file changed, 1 insertion(+)
create mode 100644 xxx.txt

[root@localhost xgp]# git status
位于分支 dev
尚未暂存以备提交的变更:
(使用 "git add <file>..." 更新要提交的内容)
(使用 "git checkout -- <file>..." 丢弃工作区的改动)

修改:      xgp.txt

修改尚未加入提交(使用 "git add" 和/或 "git commit -a") #需要提交

[root@localhost xgp]# git add * #提交

查看一下
[root@localhost xgp]# ls
xgp.txt xxx.txt #可以看到已经恢复成功

切换到master分支合并分支
[root@localhost xgp]# git merge dev
更新 88eeb08..a1a9698
Fast-forward
xgp.txt | 1 +
xxx.txt | 1 +
2 files changed, 2 insertions(+)
create mode 100644 xxx.txt

小结
修复 bug 时,我们会通过创建新的 bug 分支进行修复,然后合并,最后删除;
当手头工作没有完成时,先把工作现场 git stash 一下,然后去修复 bug,修复后,再 git stash pop,回到工作现场。

Feature 分支
软件开发中,总有无穷无尽的新的功能要不断添加进来。
添加一个新功能时,你肯定不希望因为一些实验性质的代码,把主分支搞乱了,所以,每添加一个新功能,最好新建
一个 feature 分支,在上面开发,完成后,合并,最后,删除该 feature 分支。
现在,你终于接到了一个新任务:开发代号为 Vulcan 的新功能,该功能计划用于下一代星际飞船。
于是准备开发:
[root@localhost xgp]# git checkout dev
A xx.txt
切换到分支 'dev'
[root@localhost xgp]# git checkout dev
A xx.txt
切换到分支 'dev'
[root@localhost xgp]# vim xgp.txt
[root@localhost xgp]# vim xx.txt
[root@localhost xgp]# git add *
[root@localhost xgp]# git stash
Saved working directory and index state WIP on dev: a1a9698 存储qu
HEAD 现在位于 a1a9698 存储qu
[root@localhost xgp]# git status

位于分支 dev

无文件要提交,干净的工作区
[root@localhost xgp]# git stash apply
位于分支 dev
要提交的变更:
(使用 "git reset HEAD <file>..." 撤出暂存区)

新文件:    xx.txt

尚未暂存以备提交的变更:
(使用 "git add <file>..." 更新要提交的内容)
(使用 "git checkout -- <file>..." 丢弃工作区的改动)

修改:      xgp.txt

[root@localhost xgp]# git stash list
stash@{0}: WIP on dev: a1a9698 存储qu
[root@localhost xgp]# git stash drop
丢弃了 refs/stash@{0} (0ab463ebbc4ee7f3a19cd8cadafd9ebe7b390aa9)

5 分钟后,开发完毕:
[root@localhost xgp]# git commit -m "强制删除分支"
[dev 81d2812] 强制删除分支
1 file changed, 2 insertions(+)
create mode 100644 xx.txt

切回 dev,准备合并:
[root@localhost xgp]# git checkout master
M xgp.txt
切换到分支 'master'
[root@localhost xgp]# git branch -d dev
error: 分支 'dev' 没有完全合并。
如果您确认要删除它,执行 'git branch -D dev'。
强制删除
[root@localhost xgp]# git branch -D dev
已删除分支 dev(曾为 81d2812)。

多人协作
推送分支
推送分支,就是把该分支上的所有本地提交推送到远程库。推送时,要指定本地分支,这样, Git 就会把该分支推送
到远程库对应的远程分支上:
浏览器登陆github换个密钥
Gitlab deployment and application
Gitlab deployment and application
[root@localhost ~]# ssh-keygen -t rsa -C “[email protected]“ #linux生成密钥
然后把密钥放在githup放置密钥的地方
Gitlab deployment and application
把刚刚复制的到Linux里克隆到根目录和xgp目录
Gitlab deployment and application
Gitlab deployment and application
302 cd
303 ssh-keygen -t rsa -C "[email protected]"
304 cat /root/.ssh/id_rsa.pub
305 git clone [email protected]:xgp666/xgp.git
306 git clone [email protected]:xgp666/test.git
307 cd xgp/
308 git clone [email protected]:xgp666/test.git
309 cd test/
310 git checkout -b dev
311 vim index.html
312 ls
313 git add index.html
314 git commit -m "from /xgp"
315 git push origin dev
浏览器查看一下
Gitlab deployment and application

删除远程分支
[root@localhost test]# git branch -d dev
error: 无法删除您当前所在的分支 'dev'。
[root@localhost test]# git branch -r -d origin/dev
已删除远程分支 origin/dev(曾为 63aeb0a)。
[root@localhost test]# git push origin :dev
To [email protected]:xgp666/test.git

  • [deleted] dev
    Gitlab deployment and application
    删除库

    Gitlab deployment and application
    Gitlab deployment and application
    Gitlab deployment and application
    持续集成之 Gitlab 安装
    Gitlab deployment and application
    rpm -ivh gitlab-ce-11.9.8-ce.0.el6.x86_64.rpm #安装

  1. 配置启动 gitlab
    gitlab-ctl reconfigure
  2. 查看端口
    Gitlab deployment and application
  3. 浏览器登陆
    Gitlab deployment and application

Gitlab deployment and application

Gitlab deployment and application

创建项目

Gitlab deployment and application

Gitlab deployment and application

克隆项目到本地
项目路径:
Gitlab deployment and application
Linux克隆项目
git clone [email protected]:root/xgp-demo.git
Gitlab deployment and application

336 git clone [email protected]:root/xgp-demo.git
337 cd xgp-demo/
338 vim xgp.txt
339 git add xgp.txt
340 git commit -m "test"
341 git push origin master

Modify the configuration file git
vim /etc/gitlab/gitlab.rb modify
external_url ' http://192.168.1.30 ' 13 #
initialize it, restart the
gitlab-ctl reconfigure
gitlab-ctl restart
the browser view, a long time

Gitlab deployment and application
Gitlab deployment and application

Guess you like

Origin blog.51cto.com/14320361/2450320