备份 执行备份命令: sudo gitlab-backup create #如果是使用Docker部署的: sudo docker exec -t <container name> gitlab-backup create 备份完成后会生成备份文件:<backup-id>_gitlab_backup.tar,其中的 <backup-id> 包含了备份时间、GitLab 版本等信息,例如: 1493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar 默认情况下备份的存储位置是:/var/opt/gitlab/backups 此外还应单独备份以下文件: /etc/gitlab/gitlab.rb /etc/gitlab/gitlab-secrets.json /etc/gitlab/ssl /etc/gitlab/trusted-certs 自动删除旧备份 如果想在备份时自动删除旧备份文件,可以修改备份文件的生存期,编辑 /etc/gitlab/gitlab.rb: ## Limit backup lifetime to 7 days - 604800 seconds gitlab_rails['backup_keep_time'] = 604800 修改配置文件后需执行重新配置命令才能生效: sudo gitlab-ctl reconfigure 恢复 从备份文件恢复 GitLab 需要一个可运行的实例,可以重新安装一个全新的程序,但要选用与备份文件一致的版本。恢复时原有数据会被清除! 首先应该手动恢复: /etc/gitlab/gitlab.rb /etc/gitlab/gitlab-secrets.json /etc/gitlab/ssl /etc/gitlab/trusted-certs 重新配置,执行: sudo gitlab-ctl reconfigure 将要恢复的备份文件拷贝至: /var/opt/gitlab/backups/(如果没改备份存储路径的话) 停止连接到数据库的进程: sudo gitlab-ctl stop puma sudo gitlab-ctl stop sidekiq sudo gitlab-ctl status #再次确认他们已被关闭 执行恢复命令: sudo gitlab-backup restore BACKUP=<backup-id> 例如: sudo gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce 恢复完成后重新启动并检查 GitLab: sudo gitlab-ctl restart sudo gitlab-rake gitlab:check SANITIZE=true 验证数据库的值是否可以被解密,尤其是在还原了/etc/gitlab/gitlab-secrets.json或更换了服务器: sudo gitlab-rake gitlab:doctor:secrets 为了确保恢复的可靠,还可以对上传文件做完整性检验: sudo gitlab-rake gitlab:artifacts:check sudo gitlab-rake gitlab:lfs:check sudo gitlab-rake gitlab:uploads:chec...
包含 git 标签的文章
在 Git Bash 中使用 tree 命令
关于 tree 命令 tree 命令可以以 ASCII 树状图的方式列出目录的结构。 $ tree ./tree-1.5.2.2-bin -A ./tree-1.5.2.2-bin ├── bin │ └── tree.exe ├── contrib │ └── tree │ └── 1.5.2.2 │ ├── tree-1.5.2.2 │ ├── tree-1.5.2.2-GnuWin32.README │ └── tree-1.5.2.2-src │ ├── CHANGES │ ├── INSTALL │ ├── LICENSE │ └── README ├── man │ └── cat1 │ └── tree.1.txt └── manifest ├── tree-1.5.2.2-bin.mft └── tree-1.5.2.2-bin.ver 9 directories, 9 files 注:-A 参数在绘制线条时使用 ASCII 扩展字符,这会更好看一些。 这对我们在命令行中查看目录的组织方式还是很有作用的。但 git bash 默认并没有集成该命令。我们可以自行安装一下。 安装 tree 命令 下载: 到 https://gnuwin32.sourceforge.net/packages/tree.htm 下载 Windows 版预编译二进制文件: 从下载到的压缩包中解压出可执行程序 tree.exe (单独一个文件即可),放置于 git 的安装目录 /usr/bin/(默认安装情况下绝对路径通常是 C:\Program Files\Git\usr\bin)。 这时打开 Git Bash 就可以用 tree 命令了。 $ tree --help usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] [--filelimit #] [<directory list>] -a All files are listed. -d List directories only. -l Follow symbolic links like directories. -f Print the full path prefix for each file. -i Don't print indentation lines. -q Print non-printable characters as '?'. -N Print non-printable characters as is. -p Print the protections for each file. -u Displays file owner or UID number. -g Displays file group owner or GID number. -s Print the size in bytes of each file. -h Print the size in a more human readable way. -D Print the date of last modification. -F Appends '/', '=', '*', or '|' as per ls -F. -v Sort files alphanumerically by version. -r Sort files in reverse alphanumeric order. -t Sort files by last modification time. -x Stay on current filesystem only. -L level Descend only level directories deep. -A Print ANSI lines graphic indentation lines. -S Print with ASCII graphics indentation lines. -n Turn colorization off always (-C overrides). -C Turn colorization on always. -P pattern List only those files that match the pattern given. -I pattern Do not list files that match the given pattern. -H baseHREF Prints out HTML format with baseHREF as top directory. -T string Replace the default HTML title and H1 header with string. -R Rerun tree when max dir level reached. -o file Output to file instead of stdout. --inodes Print inode number of each file. --device Print device ID number to which each file belongs. --noreport Turn off file/directory count at end of tree listing. --nolinks Turn off hyperlinks in HTML output. --dirsfirst List directories before files. --charset X Use charset X for HTML and indentation line output. --filelimit # Do not descend dirs with more than # files in them. 通常命令跟文件夹即可,文件夹可以是相对路径也可以是绝对路径,并且可以指定多个文件夹。 使用 Windows 自带的 tree 命令 我们要知道 Windows 的命令行工具自带了 tree 命令,展示细节上差点意思,将就一下也还行。 PS D:\root> tree tree-1.5.2.2-bin /F 卷 Data 的文件夹 PATH 列表 卷序列号为 6EDF-788C D:\ROOT\TREE-1.5.2.2-BIN ├─bin │ tree.exe │ ├─contrib │ └─tree │ └─1.5.2.2 │ │ tree-1.5.2.2-GnuWin32.README │ │ │ ├─tree-1.5.2.2 │ └─tree-1.5.2.2-src │ CHANGES │ INSTALL │ LICENSE │ README │ ├─man │ └─cat1 │ tree.1.txt │ └─manifest tree-1.5.2.2-bin.mft tree-1.5.2.2-bin.ver 不过由于该命令是集成在命令行程序的,所以不能被 git bash 调用。不过我想了一个注意,在 git bash 中先执行 cmd,进入 Windows 命令行环境后再执行 tree 命令,怎么样,这招是不是很高明 ...
git 推送报错 [remote rejected] shallow update not allowed
新建远程仓库,并将本地仓库的远程仓库改为新的地址后,执行 push 报错: [remote rejected] master -> master (shallow update not allowed) 原因是之前使用了 git clone --depth< number> 命令进行了浅层克隆。这样一个克隆的一个限制是你不能将它推送到一个新的存储库中。 先加回旧仓库的地址: git remote add old <path-to-old-remote> 然后执行: git fetch --unshallow old 这个命令是认为当前本地的这个目录下面是 shallow(不完整的),比较远端库和本地库,然后把没有的下载补齐。然后就可以推到新库了。 当然了,也可以抛弃历史包袱,改成新库再推送到新远程...
解决向 Jenkins( Windows) 添加 Git 仓库时报错的问题
向 Jenkins( Windows) 添加 Git 仓库时总是报错,当添加 HTTPS 仓库地址时报错: Failed to connect to repository : Command "C:\Program Files\Git\bin\git.exe ls-remote -h -- >https://git.***.com/gitlab/git.git HEAD" returned status code 128: stdout: stderr: fatal: unable to access 'https://git.***.com/gitlab/git.git/': OpenSSL SSL_connect: >SSL_ERROR_SYSCALL in connection to git.***.com:443 当添加 SSH 仓库地址时报错: Failed to connect to repository : Command "C:\Program Files\Git\bin\git.exe ls-remote -h -- >git@git.***.com:gitlab/git.git HEAD" returned status code 128: stdout: stderr: Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists...
TortoiseGit 合并过程
将本地的修改 Commit 后,push 到服务器时提示失败。这是可能是因为本地的版本落后于远程版本,服务器上的版本已经被别人抢先一步更新了。这个时候就要做一下合并操作了。所谓的合并可以是合并同一分支(比如上述往 master 分支)的不同版本,也可以是合并不同分支(比如要将 dev 分支合并到 master 分支),查看同一个文件不同版本间的差异并选择两者中的一种或发现新的问题作出新的改动,最后再 commit、push 的过程。 先 Pull,由于我们已经知道本地与服务器两个版本是不同的,所以已经预料到会有问题。 Pull 的时候会自动合并,由于 git 访问不了公司加了密的文件,所以文本文件被当成了二进制文件,自动合并不起作用,只能手动合并。不过即使能正常自动合并,也可能合并出错,毕竟机器还不能完全理解人的意图。 本地文件的图标也会发生变化,感叹号的文件就是有冲突的文件: 点击窗口或菜单中的 Resolve,开始解决冲突的过程。 弹出来冲突文件列表: 由于我使用了 Beyond Compare 做第三方比较/合并工具,所以双击文件就打开了 BC: 同时自动生成了三个文件(应该是 git 生成的,而不是 bc,用内置合并工具时也会生成这几个文件): 编辑器打开冲突文件 .gitignore,可以看到自动合并的痕迹: <<<<<<< HEAD 与 ======= 之间的内容是本地主分支上的内容,>>>>>>> c7877cc893ca1171b829ac7f48187a97befacfdd 是 远程主分支上最新版本 c7877 的内容。两个内容一样,都是相对于上一版本增加的内容。 BC 上面三列分别是 BASE、LOCAL、REMOTE,分别表示上一个版本(感觉可能是共同的祖先),本地版本,远程版本,这三个内容是只读的,改不了。下面的窗口是合并操作的输出,并不是工作区冲突的那个文件的实际内容。 把所有冲突解决掉,commit 然后 push 到服务器。 取消合并: 在 commit 前可以取消合并操作,以使工作区的文件退回到本地最新版本的状态。...