企业高效持续集成平台场景介绍
CI:持续集成、持续构建 CD:持续交互、持续部署
Maven:负责打(java)包
缺点:单点问题,成本高(2台)
安装Git
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum -y install gcc perl-ExtUtils-MakeMaker
tar xf git-2.9.5.tar.gz -C /usr/src
cd /usr/src/git-2.9.5/
./configure --prefix=/usr/local/git
make && make install
ln -sf /usr/local/git/bin/* /usr/bin/
ln -s /usr/libexec/git-core/* /usr/bin
创建目录
mkdir -p /mycode
cd /mycode
初始工作目录
git init
ll -la
touch test
git add *
git status
export LANG=zh_CN.UTF8 修改全局变量的配置文件为中文
Git commit 从暂存提交到本地仓库
git config --global user.email "715628277@qq.com"
git config --global user.name "tzf"
git commit -m “test”
Git remote 管理远程仓库
git remote add test https://github.com/tzf11/test.git #git remote add 代号 URL
git push -u test master #git push add 代号 master分支
git clone克隆一个现有仓库到本地
yum -y install git
mkdir -p /mycode2
cd /mycode2
git initgit clone https://github.com/tzf11/test.git
cd master/
echo "tttt" > tzf
git config --global user.email “715628277@qq.com”
git config --global user.name "tzf"
git add *
git commit -m “111”
git push https://github.com/tzf11/test.git
git fetch 将远程仓库的变更拉取到本地仓库
get checkout检查工作目录代码与本地仓库中的代码的差异
git merge 将远程仓库的变更,更新到本地工作目录中
git pull 将远程仓库的变更拉取到本地仓库,并更新本地工作目
git pull ====> git fetch + git merge
#在Git01上对文件进行改动,并推送到github远程仓库
[root@Git01 mycode]# ls
test
[root@Git01 mycode]# echo "welcome to yunjisuan" >> test
[root@Git01 mycode]# cat test.txt
sdfsdfsadf
welcome
wwww
welcome to yunjisuan
[root@Git01 mycode]# git add *
[root@Git01 mycode]# git commit -m "git01修改了test"
[master 4cc28a4] git01修改了test.txt
1 file changed, 1 insertion(+)
[root@Git01 mycode]# git push -u test master
Username for 'https://github.com': 715628277@qq.com
Password for 'https://715628277@qq.com@github.com':
对象计数中: 3, 完成.
压缩对象中: 100% (2/2), 完成.
写入对象中: 100% (3/3), 294 bytes | 0 bytes/s, 完成.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/tzf11/test
b666246..4cc28a4 master -> master
分支 master 设置为跟踪来自 test 的远程分支 master。
#在Git02上,拉取远程仓库的变更后直接合并进本地仓库的master分支
[root@Git02 ~]# cd /mycode2/test
[root@Git02 test]# git pull test master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
来自 https://github.com/tzf11/test
* branch master -> FETCH_HEAD
更新 b666246..4cc28a4
Fast-forward
test.txt | 1 +
1 file changed, 1 insertion(+)
[root@Git02 test]# cat test.txt
sdfsdfsadf
welcome
wwww
welcome to yunjisuan
.##通过git reset 来给已经添加到暂存区的文件撤销掉
[root@Git01 mycode]# ls
benet.txt test.txt
[root@Git01 mycode]# git status
位于分支 master
您的分支领先 'test/master' 共 2 个提交。
(使用 "git push" 来发布您的本地提交)
要提交的变更:
(使用 "git reset HEAD <文件>..." 以取消暂存)
新文件: benet.txt
[root@Git01 mycode]# git reset benet.txt
[root@Git01 mycode]# git status
位于分支 master
您的分支领先 'test/master' 共 2 个提交。
(使用 "git push" 来发布您的本地提交)
未跟踪的文件:
(使用 "git add <文件>..." 以包含要提交的内容)
benet.txt
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
git diff命令可以将本地工作目录中的文件与本地仓库中的文件进行对比
[root@Git01 mycode]# git diff test
[root@Git01 mycode]# echo "welcome" >> test
[root@Git01 mycode]# echo "welcome" >> test
[root@Git01 mycode]# git diff test
diff --git a/benet.txt b/test
index d510880..e672336 100644
--- a/test
+++ b/test
@@ -2,3 +2,5 @@ www
www
+welcome #工作目录文件与本地仓库对比,多了此行内容
git log:查看提交历史记录
git log -2 :查看最近几条记录
git log -p -1 : -p显示每次提交的内容差异
git log --stat -2 :stat简要显示数据增改行数,这样就能看到提交中修改过的内容
git log --pretty=oneline :一行显示提交的历史记录
Git还原历史数据
git reset --hard HEAD^ #–>还原历史提交版本上一次
git reset --hard 3de15d4 #–>找到历史还原点的SHA-1值后,就可以还原(值不写全,系统会自动匹配)
[root@Git01 mycode]# git reset --hard 45c319d
HEAD 现在位于 45c319d 再次改动一次test.txt
[root@Git01 mycode]# git log --pretty=oneline
45c319df640a45bf1ce0cd4e4187b106b222e93c 再次改动一次test.txt
git reflog:查看未来历史更新点
[root@Git01 mycode]# git reflog
45c319d HEAD@{0}: reset: moving to 45c319d
d9cd2d8 HEAD@{1}: reset: moving to HEAD^
d811fd3 HEAD@{2}: commit: benet.txt添加了内容 #计划还原到最初的这个版本
d9cd2d8 HEAD@{3}: reset: moving to HEAD^
0e94052 HEAD@{4}: commit: test
d9cd2d8 HEAD@{5}: merge test/master: Merge made by the 'recursive' strategy.
eed7cab HEAD@{6}: commit: tttt
540b738 HEAD@{7}: commit: test2
#还原到之前的版本
[root@Git01 mycode]# ls
test.txt
[root@Git01 mycode]# git reset --hard d811fd3
HEAD 现在位于 d811fd3 benet.txt添加了内容
[root@Git01 mycode]# ls
1 10 2 3 4 5 6 7 8 9 benet.txt test.txt
[root@Git01 mycode]# git log --pretty=oneline
d811fd378becc148db827c77ab2701df159f66bd benet.txt添加了内容
d9cd2d8777bc33a44b749005279f14c6d8d1b0f4 Merge remote-tracking branch 'test/master'
eed7cab86dd33689151bce33380126623a54bac1 tttt
71222749ac1d3c0cb64eb9cb18b52ac51dec308c test
ae42e7600b66d5368ba865b0d5b4992b11aa9c1e test
540b738327018eb201ec01e3847a584ce7e69f9a test2
cf36f74f5cfcddfa7356bd01e2b818e8c39cb31e test
2090db9778298377b90bf0bc56030cf6062a13c9 111
4cc28a41a62ebab7fb023b00e3e0ab8107a447e0 git01修改了test.txt
b6662463c1f8a0c5d04faf9e146b13c92734587a 再次改动一次test.txt
45c319df640a45bf1ce0cd4e4187b106b222e93c 再次改动一次test.txt
cb1cf08c325fab21e7ee29f67946866863fdedb2 再次改动一次test.txt
40f3e3d488d059a190652c05e8c28f52459acceb 修改了test.txt
6bff4b4c5f37c78e2a3b1e855057edbbeb4a9b4e test
git tag v1.0 : 给当前提交内容打一个标签(方便回滚)
git tag : 查看当前所有的标签
git show v1.0:查看当前1.0版本的详细信息
git tag v1.2 -m “描述”
git tag -d v1.0:删除之前的v1.0标签
[root@Git01 mycode]# git tag v1.0
v1.0
[root@Git01 mycode]# echo "www" >> benet.txt
[root@Git01 mycode]# git add *
[root@Git01 mycode]# git commit -m "test"
[master 942131a] test
1 file changed, 2 insertions(+)
[root@Git01 mycode]# git tag v2.0
[root@Git01 mycode]# git tag
v1.0
v2.0
[root@Git01 mycode]# git reset --hard v2.0 #回退到v2.0版本
#查看标签为v1.0的提交的详细变更内容
[root@Git01 mycode]# git show v1.0
commit def8bf29afbd2bd7b899bf1472f9e1d290995afe
Author: Mr.chen <215379068@qq.com>
Date: Thu Sep 13 23:08:24 2018 +0800
test3
diff --git a/benet.txt b/benet.txt
index 529c2d0..d510880 100644
--- a/benet.txt
+++ b/benet.txt
@@ -1,3 +1,4 @@
www
www
+www
[root@Git01 mycode]# git tag -d v1.0 #已删除标签 'v1.0'(曾为 942131a)
[root@Git01 mycode]# git tag
v2.0
gitignore文件
[root@Git01 mycode]# cat .gitignore
target
*.log #忽略任意开头.log结尾文件
?.idea #忽略任意一个字符开头.idea结尾文件
[root@Git01 mycode]# git add .gitignore
[root@Git01 mycode]# git status
[root@Git01 mycode]# git commit -m “提交gitignore”
[root@Git01 mycode]# git push test master
[root@Git01 mycode]# touch 1.log
[root@Git01 mycode]# git status
[root@Git01 mycode]# touch 222
[root@Git01 mycode]# git status
git branch : 查看当前分支情况,当前分支前有*号
git branch linux : 创建分支
git checkout:检查本地分支与远程分支的变更差异
git checkout linux:切换分支
[root@localhost mycode]# git branch
* master
[root@localhost mycode]# git branch linux
[root@localhost mycode]# git branch
linux
* master
[root@localhost mycode]# git checkout linux
Switched to branch 'linux'
[root@localhost mycode]# git branch
* linux
master
8.[root@Git01 mycode]# echo "linux分支新增一行" >> benet.txt
[root@Git01 mycode]# git add *
[root@Git01 mycode]# git commit -m "test"
[linux 2592cd6] test
1 file changed, 1 insertion(+)
[root@Git01 mycode]# git status
位于分支 linux
要提交的变更:
(使用 "git reset HEAD <文件>..." 以取消暂存)
修改: benet.txt
[root@Git01 mycode]# cat benet.txt
www
www
www
linux分支新增一行 #linux分支比master分支新增一行数据
切换分支到master分支
[root@Git01 mycode]# git checkout master
切换到分支 'master'
您的分支与上游分支 'test/master' 一致。
查看benet.txt文件
[root@Git01 mycode]# cat benet.txt
www
www
www
当linux的本地分支仓库和master本地分支仓库的代码不同时,如果你没把变更从暂存区提交到分支仓库,那么默认是不能切换分支的。
git merge linux : 合并linux分支到master git branch -d linux
:确定合并完成后,可以放心的删除Linux分支
[root@Git01 mycode]# git branch
linux
* master
[root@Git01 mycode]# cat benet.txt
www
www
www
[root@Git01 mycode]# git merge linux #将分支linux的变更合并到当前分支
更新 4da08fc..23e5b98
Fast-forward
benet.txt | 1 +
1 file changed, 1 insertion(+)
[root@Git01 mycode]# cat benet.txt
www
www
www
修改第一次
[root@Git01 mycode]# git branch -d linux
已删除分支 linux(曾为 23e5b98)。
[root@Git01 mycode]# git branch
* master
假如linux分支的变更没有合并到当前分支,那么必须用-D参数强制删除分支
[root@Git01 mycode]# git branch
linux
* master
[root@Git01 mycode]# git branch -d linux
error: 分支 'linux' 没有完全合并。
如果您确认要删除它,执行 'git branch -D linux'。
[root@Git01 mycode]# git branch -D linux
已删除分支 linux(曾为 7212474)
在Git01上进行操作,让linux分支和master分支产生文件代码冲突
[root@Git01 mycode]# git merge linux
自动合并 benet.txt
冲突(内容):合并冲突于 benet.txt #报错说明,冲突在benet.txt文件
自动合并失败,修正冲突然后提交修正的结果。
#找出文件冲突内容,并修改。(此时冲突的benet.txt文件里已经被标注了冲突内容)
[root@Git01 mycode]# cat benet.txt
www
www
www
test
<<<<<<< HEAD #HEAD:表示当前所在的分支
master #此行表示当前所在分支本行的master和下边的linux所在分支的linux冲突
======= #隔离符号
linux #和上边的master内容冲突
>>>>>>> linux #linux分支
#到了这里我们只能手动排除,选择保留后的内容,假如我们要保留linux分支的内容,然后再将工作目录中的变更提交即可人工解决代码冲突,并完成分支合并
[root@Git01 mycode]# vim benet.txt
[root@Git01 mycode]# cat benet.txt
www
www
www
test
linux
[root@Git01 mycode]# git add *
[root@Git01 mycode]# git commit -m "修改了一个分支冲突"
[master 001ef0b] 修改了一个分支冲突
[root@Git01 mycode]# git status
位于分支 master
您的分支领先 'test/master' 共 1 个提交。
(使用 "git push" 来发布您的本地提交)
nothing to commit, working tree clean
将linux标签推送到github远程仓库的linux分支
#创建本地标签,并推送到github
[root@Git01 mycode]# git tag v1.0 -m "这就是一个测试"
[root@Git01 mycode]# git tag
v1.0
[root@Git01 mycode]# git push test v1.0
Username for 'https://github.com': 715628277@qq.com
Password for 'https://215379068@qq.com@github.com':
对象计数中: 1, 完成.
写入对象中: 100% (1/1), 183 bytes | 0 bytes/s, 完成.
Total 1 (delta 0), reused 0 (delta 0)
To https://github.com/tzf11test.git
* [new tag] v1.0 -> v1.0
通过git clone -b linux URL(直接指定远程仓库分支进行克隆) mycode (改名)
创建gitlab仓库
[root@localhost ~]# cd /home
[root@localhost home]# ls
git
[root@localhost home]# mkdir app
[root@localhost home]# useradd git
[root@localhost home]# chown -R git.git git
(密码:123123)