git gc
git
書き方
git gc [--aggressive] [--prune=<date>]散らばったオブジェクトをまとめ、誰も使わないものを捨てて.gitを小さくします。--prune=nowはreflogが抱えていたコミットまで捨てるので、resetを取り消す安全網が無くなります。
よく使うオプション
| オプション | 意味 |
|---|---|
| --aggressive | repack harder; slow, occasionally worth it |
| --prune=<date> | drop unreachable objects older than that |
| --prune=now | drop them all, which also throws away reflog-only commits |
| --auto | do nothing unless there is enough loose junk |
| --no-prune | repack but keep unreachable objects |
| -q | no progress output |
例
git gcpacks loose objects and shrinks .git
git gc --autothe cheap check git itself runs after some commands
git gc --prune=now --aggressivesmallest 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