169

Git设置代理克隆Github代码

http方式克隆

git clone -c https.proxy="127.0.0.1:7890" <仓库地址>

ssh方式克隆

编辑配置文件~/.ssh/config,加入如下配置

Host github.com
        HostName github.com
        User git
        ServerAliveInterval 60
        # 走 HTTP 代理
        ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=7890
        # 走 socks5 代理 linux
        #ProxyCommand nc -v -x 127.0.0.1:7890 %h %p
        # 走 socks5 代理 windows
        #ProxyCommand connect -S 127.0.0.1:7890 %h %p

然后,直接克隆代码即可

187

Git实用操作备忘

克隆指定分支

git clone -b --depth=1 <分支名称> <仓库地址>

说明:--depth=1 表示只克隆最近一次commit的分支完整内容,这样克隆的项目就不会很大

关闭git输出信息分页器

git config --global --replace-all core.pager "less -F -X"

删除全局配置

git config --global --unset user.name

编辑全局配置

git config --global --edit

查看提交的具体内容

git show commit_id

删除所有远程标签

git show-ref --tag | awk '{print ":" $2}' | xargs git push origin

删除所有本地标签

git tag -l | xargs git tag -d
192

Windows下的 Git-bash 增加zip 和 unzip 工具

git-bash默认是没有zip和unzip命令的,我们可以通过手动安装方式,增加该命令。

  1. 下载zip以及bzip2,因为zip依赖bzip2.dll
  2. 将zip-3.0-bin.zip和bzip2-1.0.5-bin.zip解压,拷贝zip.exe 和 bzip2.dll 到 Git安装目录下的 \usr\bin 目录中

下载文件:
zip-3.0-bin.zip

bzip2-1.0.5-bin.zip

700

Git瘦身,删除历史大文件

找到大文件

git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -g | tail -5

查看文件路径

git rev-list --objects --all | grep <ID>

查看前因后果,历史提交。以public/test.mp4为例

git log --pretty=oneline --branches -- public/test.mp4

如果需要知道commit id所在的分支,使用命令

git branch -a --contains <COMMIT ID>

删除大文件

23001

gogs搭建私有git服务器

安装mysql

参见之前的文章:https://dotatong.cn/index.php/archives/1/

安装gogs

二进制文件官方地址 https://gogs.io/docs/installation/install_from_binary