持续集成

警告
本文最后更新于 2022-07-05,文中内容可能已过时。

持续集成

DevOps 是一个框架,是一种理论方法,并不是一套工具,他包括一系列的基本原则和实践。其核心价值着重于更快速的交付,响应市场的变化。更多的关注业务的改进与提升。

git

工作目录-暂存区域(git add)-本地仓库(git commit)-远程仓库(git push)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$> git config --global user.name 0x5c0f
$> git config --global user.email mail@0x5c0f.cc
$> cat ~/.gitconfig # 系统层面位于/etc/ 下 ; 项目层面,项目根目录
[user]
	name = 0x5c0f
	email = mail@0x5c0f.cc

$> git config  --list
user.name=0x5c0f
user.email=mail@0x5c0f.cc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$> mkdir /data/gittest -p && cd /data/gittest 
$> git init 
$> tree -a 
.
└── .git
    ├── branches
    ├── config
    ├── description
    ├── HEAD
    ├── hooks
    ......
    ├── objects     
    │   ├── info
    │   └── pack 
    ...... 

# 移除缓冲区文件 
$> git rm --cached <file>

# 移除本地及缓冲区文件     
$> git rm -f <file>

# 重命名 
$> mv <file> <file>.txt 
$> git rm --cached <file>
$> git add <file>.txt       # git commit -m ""

# 查看修改详情 
$> git diff <file>         

# 查看提交历史 
$> git log 

# 查看提交历史(精简)
$> git log --oneline 

# 撤回修改文件(未add时) 
$> git checkout -- <file>

# 撤回修改文件(未commit时) 
$> git reset HEAD <file>    # git checkout -- <file>

# 撤回修改文件(未push时)
$> git reset --hard <commitid>

# 查看历史操作记录 
# 此命令大体执行在git reset --hard <commitid> 之后,因为执行了git reset --hard <commitid>后,git log将不再看到commitid之后的所有提交记录 
$> git reflog

分支创建后,直接增删,各个分支不受影响

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 创建分支 
$> git branch test01    # 删除 git branch -d test01
# 查看分支 
$> git branch
* master
  test01

# 切换分支 
$> git checkout test01  # git status    # git log --oneline --decorate  

# 合并分支(比如:合并test01到master中,则当前需要切换到master中执行)
# 当两个分支中,同时修改了一个文件,则会出现合并冲突,此时需要手动处理冲突文件 
$> git merge test01  

标签可以作为一个commitid的惟一标记,相当于给commitid取的别名吧

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 给当前commit创建标签
$> git tag v1.0     # git tag -a v1.0   # -a: 打开注释编辑页面 可使用-m "message"替代  
# 针对特定commit打标签
$> git tag v1.0 <commitid>
# 查看所有标签
$> git tag 

# 查看当前标签的详细信息 
$> git show v1.0 

# 删除标签 
$> git tag -d v1.0 

# 重置到某个标签(提交点)
$> git reset --hard v1.0  # or git reset --hard <commit>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22

$> git remote add origin http://xxxxxxx/xxx.git
$> git push -u origin master

## gitlab 备份(/etc/gitlab.rb)
# 备份路径
gitlab_rails['backup_path'] = '/data/backup'
# 备份保留时间(秒)
gitlab_rails['backup_keep_time'] = 604800

# 执行备份
$> /usr/bin/gitlab-rake gitlab:backup:create


# 数据恢复 
# 停止数据写入服务
$> gitlab-ctl stop unicorn
$> gitlab-ctl stop sidekiq

$> gitlab-rake gitlab:backup:restore BACKUP=<备份文件的数字部分>  # 回车一路yes

$> gitlab-ctl restart