git常见问题

本文最后更新于:2025年1月18日 晚上

gerrit draft and topic |: https://breezetemple.github.io/2019/08/30/gerrit-draft-and-topic/

Gerrit相对Git提供了一个特有的命名空间refs/for/用来定义我们的提交上传到哪个branch,且可以用来区分我们的commit是提交到Gerrit进行审核还是直接提交到Git仓库,格式如下:

refs/for/

Push 一个 Commit 到 Gerrit: git push origin HEAD:refs/for/master
直接 Push 一个 commit 到 Git 仓库:(默认配置成不允许) git push origin HEAD:master
当commit Push到Gerrit等待review时,Gerrit会将此commit保存在一个名为refs/changes/xx/yy/zz的一个暂存branch中。

zz为这个commit的patch set号
yy是change号
xx是change号的后两位

Draft
refs/drafts/

$ git push origin HEAD:refs/drafts/xxx
在Gerrit中点击Publish按钮转换为正式Change

Topic
refs/for/
refs/for//

$ git push origin HEAD:refs/for/xxx%topic=123
$ git push origin HEAD:refs/for/xxx/123
Topic用于归类相关的提交,可以用上述的命令,同时可以在Gerrit中编辑Topic

代理

为 http 设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 一次性代理
git clone -c http.proxy="http://127.0.0.1:1087" https://github.com/
# 全局设置代理
#仅为github.com设置socks5代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1086

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

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

#取消

git config --global --unset http.proxy

git config --global --unset https.proxy

为 ssh 协议设置代理

下文配置其中的ip和端口修改成你自己代理的参数

windows

修改C:\Users${your username}.ssh目录下的config文件,若没有则新建

1
2
3
4
5
Host github.com                                                
Hostname ssh.github.com
Port 443
User git
ProxyCommand connect -S 127.0.0.1:7890 %h %p

Linux、MacOS

修改~/.ssh目录下的config文件,若没有则新建

1
2
3
4
5
Host github.com
Hostname ssh.github.com
Port 443
User git
ProxyCommand nc -v -x 172.28.208.1:7890 %h %p

验证

ssh -T git@github.com

若出现错误,则删除.ssh目录中known_hosts文件重试

Git 为 ssh 协议设置代理 - Seepine’s Blog


git常见问题
https://iwesley.top/article/ca7dd2f8/
作者
Wesley
发布于
2024年11月17日
许可协议