备份还原Gitlab

1、查看gitlab版本

gitlab-rake gitlab:env:info
System information
...
GitLab information
Version:        12.2.8
...
GitLab Shell
Version:        9.3.0
...

2、备份gitlab

gitlab-rake gitlab:backup:create
#会在这个路径生成新的备份文件
/var/opt/gitlab/backups/XXX_gitlab_backup.tar

3、准备新服务器
在新服务器上安装相同版本的gitlab,并将备份文件拷贝到新服务器相同路径

4、还原

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=XXX
gitlab-ctl start  

5、验证

gitlab-rake gitlab:check SANITIZE=true

Git06传输大repository失败

1、最近接手了一个项目,下载代码时,总会报错

git clone https://e.coding.net/xxx/xxx.git
error: RPC failed; curl 18 transfer closed with outstanding read data remaining

2、有建议说将缓存设置大一些,但没有用

#524288000单位为Byte,524288000B也就是 500MB
git config --global http.postBuffer 524288000

#1G
git config --global http.postBuffer 1048576000

3、最后将下载方式从https改为ssh方式就好了

ssh-keygen -t rsa -C "neohope@yahoo.com"
GIT_SSH_COMMAND="ssh -i /PATH_TO_ISA/xxx.rsa" git clone git@e.coding.net:xxx/xxx.git

SVN禁止提交时不写注释

最常用的方法,就是使用SVN提供的pre-commit钩子。
具体做法是,在对应的repository下的hooks文件夹下中,新建对于的pre-commit脚本,来禁止提交。

1.windows下pre-commit.bat

@echo off
setlocal

set REPOS=%1
set TXN=%2

rem 保证输入8个字符
svnlook log %REPOS% -t %TXN% | findstr "........" > nul
if %errorlevel% gtr 0 goto :err_action

rem 过滤空格字符
svnlook log %REPOS% -t %TXN% | findstr /ic:"        " > nul
if %errorlevel% gtr 0 goto :success

:err_action
echo 备注信息验证失败。                >&2
echo 提交代码时,必须填写备注信息。    >&2
echo 备注信息不少于8个字符(或4个汉字)。>&2
goto :err_exit


:err_exit
exit 1

:success
exit 0

2.linux下pre-commit.sh

#!/bin/sh

REPOS="$1"
TXN="$2"

SVNLOOK=/usr/local/bin/svnlook
LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`

#要求注释不能少于8个字符,您可自定义
if ["$LOGMSG" -lt 8];
then
  echo -e "\n备注信息验证失败。\n提交代码时,必须填写备注信息。\n备注信息不少于8个字符(或4个汉字)。" 1>&2
  exit 1
fi 

exit 0

Git04设置代理

1、设置http代理

git config --global https.proxy "http://127.0.0.1:1080"
git config --global https.proxy "https://127.0.0.1:1080"

2、设置socket代理

git config --global http.proxy "socks5://127.0.0.1:9527"
git config --global https.proxy "socks5://127.0.0.1:9527"

3、取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy

GitHub03SSH授权

用低版本的github做上传的时候,会有提示

Permission denied (publickey). 

最简单的方法,就是安装新版本的GitHub。

如果你实在不愿意升级,那可以用以下步骤来进行:

#1、测试ssh,会提示Permission denied (publickey). 
ssh -T git@github.com 
#2、生成新的授权文件,如果你没有改过配置,那文件名为github_rsa,密码保持为空即可
ssh-keygen -t rsa -C "neohope@yahoo.com"
#3、查看新的key
ssh-add -l
#4、登录GitHub网站,到管理SSH Keys的地方,上传public key
#~/.ssh/github_rsa.pub
#5、测试ssh,会提示成功
ssh -T git@github.com 

搞定!

Git02常用命令

1、设置个人信息

git config --global user.name "xxx"
git config --global user.email "xxx@xxx.xxx"

2、提交

#初始化本地git
cd hello-git
git init

#新建README文件
touch README
git add README

#提交文件到本地Git
git commit -m 'first commit'

#提交文件到远程Git
git remote add origin git@github.com:username/hello-git.git
git push -u origin master

3、取回

git clone git@github.com:username/hello-git.git

取回(包含子模块)

git clone --recursive -j6 git@github.com:username/hello-git.git

取回(包含子模块)

git clone git@github.com:username/hello-git.git
cd hello-git
git submodule update --init --recursive

4、Fork

#产生Fork后取回
git clone git@github.com:username/hello-git.git
cd hello-git

#追加上级代码信息
git remote add upstream git://github.com/SomeOne/hello-git.git
git fetch upstream
#合并上级代码
git fetch upstream
git merge upstream/master

5、创建分支

#创建分支
git checkout -b mybranch

6、合并分支

#合并分支
git checkout master
git merge mybranch
git branch -d mybranch

7、改变远程库地址

git remote set-url origin 新地址

Git01常用命令

Git基本没有主次仓库之分,十分适合团队开发;
Git的分支功能比SVN要强悍很多。

1.全局设置

#用户
git config --global user.name "your name" 
#邮箱
git config --global user.email "your email" 
#编辑器
git config --global core.editor "your editor path"

2.新建库
备份,并cd到项目目录

#初始化
git init
#添加文件
#忽略文件列表添加到文本文件.gitignore
git add .
#提交
git commit
#或快速提交
git commit -m "message"

3.提交更新

#添加文件
git add filename
#或添加所有文件
git add .
#提交
git commit -a

4.查看日志

#日志
git log
#详细日志
git log --stat --summary
#显示某一版本日志
git show vidhead
#显示某一版本前一个版本
git show vidhead^
#显示某一版本前4个版本
git show vidhead~4

5.版本恢复

#恢复某个文件
git reset vidhead filelist

6.克隆git库
cd到新的项目路径

git clone source-path

7.合并git库
cd到自己的项目路径

#将别人的库合并到自己的库
git pull source-path
#将自己的库合并到别人的库
git push target-path

8.建立赤裸仓库

git --bare init --shared

9.项目分支

#列出分支
git branch
#新建分支
git branch branchname
#切换分支
git checkout branchname
#合并分支
git merge branchname
#删除分支
git branch -d branchname
#强制删除分支
git branch -D branchname