0%

Gerrit & Git 路径自动替换小记

仓库地址自动替换:

git config --global url."ssh://username@gerrit.example.org:29418/".insteadof "ssh://gerrit.example.org/" --replace-all
git config --global url."ssh://username@gerrit.example.org:29418/".insteadof "ssh://gerrit.example.org:29418/" --add
git config --global url."ssh://username@gerrit.example.org:29418/".insteadof "http://gerrit.example.org:8080/" --add
git config --global url."ssh://username@gerrit.example.org:29418/".insteadof "http://UserName@gerrit.example.org:8080/" --add
  1. 访问 ssh://gerrit.example.org/ / ssh://gerrit.example.org:29418/ / http://gerrit.example.org:8080/ / http://UserName@gerrit.example.org:8080/ 会被自动替换成 ssh://username@gerrit.example.org:29418/.
  2. 其中 insteadof 还支持正则表达式.

也可以手动编辑 .gitconfig 文件:

[url "ssh://username@gerrit.example.org:29418/"]
	insteadof = ssh://gerrit.example.org/
	insteadof = ssh://gerrit.example.org:29418/
	insteadof = http://gerrit.example.org:8080/
	insteadof = http://UserName@gerrit.example.org:8080/