CI/CD
CI/CD:持续集成,持续交付
git应用
git是开源的分布式版本控制系统,高效处理任何大小项目
git三个重要的工作区域
工作区:项目目录
暂存区:工作区和版本库之间的缓冲地带,也叫stage
或index
。位于.git/index
版本库:快照存储区域,工作区下的.git目录
文件状态
未跟踪:工作区中的文件,尚未执行add操作
已跟踪:
已暂存:通过git add将文件放到暂存区
未修改:git commit后,没有再做修改。工作区文件内容与版本库中的一致
已修改:git commit后,修改文件,但是没有执行git add操作
安装配置
[root@gitlab ~]# git config --global user.name hepeng
[root@gitlab ~]# git config --global user.email hepeng@163.com
[root@gitlab ~]# git config --global core.editor vim
[root@gitlab ~]# git config --list
user.name=hepeng
user.email=hepeng@163.com
core.editor=vim
创建版本库,一,
[root@gitlab ~]# mkdir projects; cd projects
[root@gitlab projects]# git init mytest
初始化空的 Git 版本库于 /root/projects/mytest/.git/
[root@gitlab projects]# ls
mytest
[root@gitlab projects]# ls -A mytest/
.git
创建版本库,二,
[root@gitlab projects]# mkdir myweb; cd myweb
[root@gitlab myweb]# ls
[root@gitlab myweb]# echo 'Hello World' > readme.md
[root@gitlab myweb]# git init
初始化空的 Git 版本库于 /root/projects/myweb/.git/
[root@gitlab myweb]# ls
readme.md
[root@gitlab myweb]# ls -A
.git readme.md
[root@gitlab myweb]# ls -a
. .. .git readme.md
[root@gitlab myweb]# ls .git/
branches config description HEAD hooks info objects refs
[root@gitlab myweb]# git status
# 位于分支 master
#
# 初始提交
#
# 未跟踪的文件:
# (使用 "git add <file>..." 以包含要提交的内容)
#
# readme.md
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
暂存目录下所有文件
[root@gitlab myweb]# git add .
[root@gitlab myweb]# git status
# 位于分支 master
#
# 初始提交
#
# 要提交的变更:
# (使用 "git rm --cached <file>..." 撤出暂存区)
#
# 新文件: readme.md
#
[root@gitlab myweb]# git commit -m "project init"
[master(根提交) b6b59f8] project init
1 file changed, 1 insertion(+)
create mode 100644 readme.md
添加新文件,修改旧文件,将.txt .swp .gitignore不推送到暂存区
[root@gitlab myweb]# echo '2nd line' >> readme.md
[root@gitlab myweb]# git status
# 位于分支 master
# 尚未暂存以备提交的变更:
# (使用 "git add <file>..." 更新要提交的内容)
# (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
# 修改: readme.md
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
[root@gitlab myweb]# echo '11-25 xxxxxx' > plan.txt
[root@gitlab myweb]# echo '11-26 yyyyyy' > plan.txt
[root@gitlab myweb]# vim .gitignore
paln.txt
*.swp
.gitignore
*.txt
[root@gitlab myweb]# git status
# 位于分支 master
# 尚未暂存以备提交的变更:
# (使用 "git add <file>..." 更新要提交的内容)
# (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
# 修改: readme.md
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
丢弃工作区改动
[root@gitlab ~]# mkdir jenkins
[root@gitlab ~]# cp jenkins-2.235.1-1.1.noarch.rpm jenkins
[root@gitlab ~]# cd jenkins/
[root@gitlab jenkins]# ls
jenkins-2.235.1-1.1.noarch.rpm
[root@gitlab jenkins]# git init .
初始化空的 Git 版本库于 /root/jenkins/.git/
[root@gitlab jenkins]# ls
jenkins-2.235.1-1.1.noarch.rpm
[root@gitlab jenkins]# ls -A
.git jenkins-2.235.1-1.1.noarch.rpm
[root@gitlab jenkins]# git add .
[root@gitlab jenkins]# ls
jenkins-2.235.1-1.1.noarch.rpm
[root@gitlab jenkins]# rm -rf *
[root@gitlab jenkins]# du -sh
64M .
[root@gitlab jenkins]# ls
[root@gitlab jenkins]#
[root@gitlab jenkins]# git checkout *
[root@gitlab jenkins]# ls
jenkins-2.235.1-1.1.noarch.rpm
[root@gitlab jenkins]# du -sh jenkins-2.235.1-1.1.noarch.rpm
64M jenkins-2.235.1-1.1.noarch.rpm
撤出暂存区
[root@gitlab myweb]# echo 'hello World' > readme.md
[root@gitlab myweb]# cat readme.md
hello World
[root@gitlab myweb]# ls
readme.md
[root@gitlab myweb]# echo 'haha' >> readme.md
[root@gitlab myweb]# git add .
[root@gitlab myweb]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 修改: readme.md
#
[root@gitlab myweb]# git reset HEAD readme.md
重置后撤出暂存区的变更:
M readme.md
[root@gitlab myweb]# git status
# 位于分支 master
# 尚未暂存以备提交的变更:
# (使用 "git add <file>..." 更新要提交的内容)
# (使用 "git checkout -- <file>..." 丢弃工作区的改动)
#
# 修改: readme.md
#
修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
[root@gitlab myweb]# cat readme.md
hello World
haha
[root@gitlab myweb]# echo 'xixi' >> readme.md
[root@gitlab myweb]# git add .
[root@gitlab myweb]# git commit -m " add readme.md"
[master 67929dc] add readme.md
1 file changed, 3 insertions(+), 1 deletion(-)
[root@gitlab myweb]# git status
# 位于分支 master
无文件要提交,干净的工作区
[root@gitlab myweb]#
移动
[root@gitlab myweb]# ls
readme.md
[root@gitlab myweb]# git mv readme.md readme
[root@gitlab myweb]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 重命名: readme.md -> readme
#
[root@gitlab myweb]# git commit -m "modify readme.md => readme"
[master b7b2e26] modify readme.md => readme
1 file changed, 0 insertions(+), 0 deletions(-)
rename readme.md => readme (100%)
删除
[root@gitlab myweb]# git rm readme
rm 'readme'
[root@gitlab myweb]# ls
[root@gitlab myweb]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 删除: readme
#
[root