LoginSignup
1
0

More than 1 year has passed since last update.

大きすぎるファイルをgit add してないか確認する方法

Last updated at Posted at 2022-09-22

巨大なファイルを誤ってコミットし、レポジトリを肥大化させると大変です。何度も事故を起こしたのでステージに乗ったファイルを大きい順に表示するコマンドを組みました。

結論

git status --porcelain | grep ^[AM] | sed -e "s,^\S ,,g" | xargs -r ls -hsS
このコマンドを打つとgit add したファイルを容量が大きい順に並べて表示してくれます。便利。

git statusからgrepで変更するファイルを抜き出し、sedでパスだけ抽出し、lsで容量順に表示しているだけです

使用例

$ git status --porcelain | grep ^[AM] | sed -e "s,^\S ,,g" | xargs -r ls -hsS
 29M wave-propagation-h135-correct-2/OUTPUT/XUDISA.DAT
 29M wave-propagation-h135-correct-2/INPUT/XUDISA.DAT
4.4M wave-propagation-h135-correct-2/OUTPUT/TYPEMOVE.DAT
4.4M wave-propagation-h135-correct-2/INPUT/TYPEMOVE.DAT
2.7M wave-propagation-h135-correct-2/OUTPUT/REALTIME.XUD
...

左がファイルサイズ、右がパスです。29MBの大きいファイルをgit addしてしまったことにすぐ気づけますね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0