git gc

git

書き方

git gc [--aggressive] [--prune=<date>]

散らばったオブジェクトをまとめ、誰も使わないものを捨てて.gitを小さくします。--prune=nowはreflogが抱えていたコミットまで捨てるので、resetを取り消す安全網が無くなります。

よく使うオプション

オプション意味
--aggressiverepack harder; slow, occasionally worth it
--prune=<date>drop unreachable objects older than that
--prune=nowdrop them all, which also throws away reflog-only commits
--autodo nothing unless there is enough loose junk
--no-prunerepack but keep unreachable objects
-qno progress output

git gc

packs loose objects and shrinks .git

git gc --auto

the cheap check git itself runs after some commands

git gc --prune=now --aggressive

smallest result, and no way back to lost commits

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git gc は何をしますか。

散らばったオブジェクトをまとめ、誰も使わないものを捨てて.gitを小さくします。--prune=nowはreflogが抱えていたコミットまで捨てるので、resetを取り消す安全網が無くなります。

Q. どう打ちますか。

git gc [--aggressive] [--prune=<date>] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-gc