CI/CD

CI/CD

CI/CD:持续集成,持续交付

git应用

git是开源的分布式版本控制系统,高效处理任何大小项目

git三个重要的工作区域
工作区:项目目录
暂存区:工作区和版本库之间的缓冲地带,也叫stageindex。位于.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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值