zaki work log

作業ログやら生活ログやらなんやら

[Git] リモートリポジトリとの通信状況などのログを出力する

git clonegit pushでやたら時間がかかる場合などに、どこにボトルネックがあるかを確認するためにログを表示させる。

Gitのトレースログの有効化

Git環境変数で指定。
いろいろあるので状況に応じて試す。複数指定可能。

git-scm.com

HTTP接続の状態を確認したい場合は GIT_CURL_VERBOSE を使う。

$ GIT_CURL_VERBOSE=true git clone https://github.com/zaki-lknr/r2tokimeki.git
Cloning into 'r2tokimeki'...
10:46:38.052623 http.c:877              == Info: Couldn't find host github.com in the .netrc file; using defaults
10:46:38.210428 http.c:877              == Info: Host github.com:443 was resolved.
10:46:38.210454 http.c:877              == Info: IPv6: (none)
10:46:38.210457 http.c:877              == Info: IPv4: 20.27.177.113
10:46:38.210500 http.c:877              == Info:   Trying 20.27.177.113:443...
10:46:38.216419 http.c:877              == Info: Connected to github.com (20.27.177.113) port 443
:
:
:

パケットのトレースはGIT_TRACE_PACKETを使う。
パケットダンプしてるわけではないが流れを確認できる。

$ GIT_TRACE_PACKET=true git clone https://github.com/zaki-lknr/r2tokimeki.git
Cloning into 'r2tokimeki'...
:
:
10:58:54.877734 pkt-line.c:85           packet:     sideband< \2Compressing objects:  98% (58/59)\15
10:58:54.877738 pkt-line.c:85           packet:     sideband< \2Compressing objects: 100% (59/59)\15
10:58:54.877743 pkt-line.c:85           packet:     sideband< \2Compressing objects: 100% (59/59), done.
remote: Compressing objects: 100% (59/59), done.
10:58:54.878662 pkt-line.c:85           packet:     sideband< PACK ...
10:58:54.886004 pkt-line.c:85           packet:     sideband< \2Total 102 (delta 52), reused 81 (delta 40), pack-reused 0 (from 0)
remote: Total 102 (delta 52), reused 81 (delta 40), pack-reused 0 (from 0)
10:58:54.886022 pkt-line.c:85           packet:     sideband< 0000
10:58:54.886029 pkt-line.c:85           packet:          git> 0002
Receiving objects: 100% (102/102), 87.87 KiB | 12.55 MiB/s, done.
Resolving deltas: 100% (52/52), done.
10:58:54.913838 pkt-line.c:85           packet:        clone< 0002

Gitの内部処理を出力したい場合はGIT_TRACEで確認できる。

$ GIT_TRACE=true git clone https://github.com/zaki-lknr/r2tokimeki.git
10:52:00.201443 git.c:476               trace: built-in: git clone https://github.com/zaki-lknr/r2tokimeki.git
Cloning into 'r2tokimeki'...
10:52:00.203026 run-command.c:667       trace: run_command: git remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
10:52:00.203045 run-command.c:759       trace: start_command: /usr/libexec/git-core/git remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
10:52:00.204325 git.c:772               trace: exec: git-remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
10:52:00.204365 run-command.c:667       trace: run_command: git-remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
10:52:00.204393 run-command.c:759       trace: start_command: /usr/libexec/git-core/git-remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
10:52:01.323100 run-command.c:667       trace: run_command: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 14855 on cloud-dev2' --check-self-contained-and-connected
:
:

併用も可能。

$ GIT_CURL_VERBOSE=true GIT_TRACE=true  git clone https://github.com/zaki-lknr/r2tokimeki.git
11:04:44.094702 git.c:476               trace: built-in: git clone https://github.com/zaki-lknr/r2tokimeki.git
Cloning into 'r2tokimeki'...
11:04:44.096163 run-command.c:667       trace: run_command: git remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
11:04:44.096182 run-command.c:759       trace: start_command: /usr/libexec/git-core/git remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
11:04:44.097493 git.c:772               trace: exec: git-remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
11:04:44.097539 run-command.c:667       trace: run_command: git-remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
11:04:44.097561 run-command.c:759       trace: start_command: /usr/libexec/git-core/git-remote-https origin https://github.com/zaki-lknr/r2tokimeki.git
11:04:44.101275 http.c:877              == Info: Couldn't find host github.com in the .netrc file; using defaults
11:04:44.102408 http.c:877              == Info: Host github.com:443 was resolved.
:
:

Gitのverboseオプション

簡易的な情報であればGit自体の--verboseオプションもある。(が、情報量は少ない)

$ git clone -v https://github.com/zaki-lknr/r2tokimeki.git
Cloning into 'r2tokimeki'...
POST git-upload-pack (181 bytes)
POST git-upload-pack (408 bytes)
remote: Enumerating objects: 102, done.
remote: Counting objects: 100% (102/102), done.
remote: Compressing objects: 100% (59/59), done.
remote: Total 102 (delta 52), reused 81 (delta 40), pack-reused 0 (from 0)
Receiving objects: 100% (102/102), 87.87 KiB | 12.55 MiB/s, done.
Resolving deltas: 100% (52/52), done.

sshのverboseオプション

リポジトリsshでアクセスしている場合に、ssh -vを使って接続すれば、/usr/bin/sshの接続ログが出力される。
ログ量を増やすには-vvvのようにverboseレベルを増やす。

$ GIT_SSH_COMMAND="ssh -v" git clone git@github.com:zaki-lknr/bsky-client.git
Cloning into 'bsky-client'...
OpenSSH_9.9p1, OpenSSL 3.2.4 11 Feb 2025
debug1: Reading configuration data /home/zaki/.ssh/config
debug1: /home/zaki/.ssh/config line 1: Applying options for *
debug1: /home/zaki/.ssh/config line 4: Applying options for github.com
:
:

Appendix