git操作github-gitlab

克隆

有两种方式,一种是通过ssh,一种是通过http

使用ssh的方式需要在本机生成ssh文件,
参考资料:https://gitlab.followme.com/help/ssh/README#generating-a-new-ssh-key-pair

产生SSH

To create a new SSH key pair:
Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.

1
2
3
4
5
Generate a new ED25519 SSH key pair:
ssh-keygen -t ed25519 -C "email@example.com"

Or, if you want to use RSA:
ssh-keygen -o -t rsa -b 4096 -C "email@example.com"

Adding an SSH key to your GitLab account

Copy your public SSH key to the clipboard by using one of the commands below
depending on your Operating System:

1
2
3
4
5
6
7
8
macOS:
pbcopy < ~/.ssh/id_ed25519.pub

WSL / GNU/Linux (requires the xclip package):
xclip -sel clip < ~/.ssh/id_ed25519.pub

Git Bash on Windows:
cat ~/.ssh/id_ed25519.pub | clip

go mod 中下载依赖包时,可以使用

go build .
但是下载有时候会出现问题,例如:
我运行go mod download 提示 fatal: could not read Username for ‘https://gitlab.XXX.com’: terminal prompts disabled

这时,需要通过ssh的方式下载gitlab中的数据:

1
vim ~/.gitconfig

添加:

1
2
[url "ssh://git@gitlab.XXX.com/"]
insteadOf = https://gitlab.XXX.com/

查看分支

1
git branch -a

将远程分支 dev 到本地dev 并切换到dev分支

1
2
3

git fetch origin dev 存疑
git checkout -b dev origin/dev

1
2
3
git push origin dev

git push -f origin dev 强制更新

删除文件

1
git rm --cached -r .idea

添加远程

1
2
3
4
5
git remote add camel-snipet git@gitlab.followme.com:camel/go-snipet.git

git remote -v

git push camel-snipet dev

回退

1
2
git reflog
git reset --hard a7e1d279

mac添加环境变量

1
2
3
4
5
6
7
操作步骤:
1、打开Terminal(终端)
2、输入:vim ~/.bash_profile
3、设置PATH:export PATH=/usr/local/mysql/bin:$PATH
4、输入::wq //保存并退出vi
5、修改立即生效:source ~/.bash_profile
6、查看环境变量的值:echo $PATH

go run main.go --registry=consul --registry_address=“127.0.0.1:8500”

consul:
自动将服务添加到consul
UI :http://localhost:8500

##gitlab Runner

To install GitLab Runner using Homebrew:

Install the GitLab Runner.

brew install gitlab-runner

Install the Runner as a service and start it.

brew services start gitlab-runner

Runner is installed and running.

gitlab-runner register
gitlab-runner stop
gitlab-runner register
gitlab-runner unregister --all-runners

./gitlab-runner run

当远程分支有冲突,强制

git fetch --all
git reset --hard origin/master

merge

git merge -Xtheirs dev
git merge -Xours dev

工作区回到最后一次提交的状态。

git checkout .

git log --pretty=oneline

但最有意思的是 format,可以定制要显示的记录格式,这样的输出便于后期编程提取分析,像这样:

$ git log --pretty=format:"%h - %an, %ar : %s"
ca82a6d - Scott Chacon, 11 months ago : changed the version number
085bb3b - Scott Chacon, 11 months ago : removed unnecessary test code
a11bef0 - Scott Chacon, 11 months ago : first commit

makefile 代码片段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
proto:
for d in api srv; do \
for f in $$d/**/proto/*.proto; do \
protoc --proto_path=${GOPATH}/src --micro_out=. --go_out=. $$f; \
echo compiled: $$f; \
done \
done

lint:
./bin/lint.sh

build:
./bin/build.sh

data:
go-bindata -o data/bindata.go -pkg data data/*.json

run:
docker-compose build
docker-compose up