在開大型 git project (e.g. linux) 的 log 時, 常會花上幾秒鐘的時間讀取.
原因是 git 需要重複做以下動作: 讀取 commit 的 content –> 找到 parent commit –> 讀取 parent commit 的 content –> (loop).
為了加速 log 的讀取, git 提供了 git commit-graph
指令來建立一個簡化 parrent commit 讀取速度的簡易 graph database.
git commit-graph write --reachable
git show-ref -s | git commit-graph write --stdin-commits
git rev-parse HEAD | git commit-graph write --stdin-commits --append
生成的 commit graph 會放在 .git/objects/info/commit-graph
.
Commit graph 裡包含 object ID, parent relationships, commit date and root tree information.
Method 1:
git config fetch.writeCommitGraph=true
Method 2:
git maintenance start
Git
Written on
September
24th,
2022
by
Borting