Search code examples
gitgithublarge-files

Removing unpushed commits


Follow up to:

Git push fails for large number of commits

Looking at file sizes:

2,8G    ./.git/objects/pack/pack-ccd569220702533a66bd570822dc3f99508a173c.pack
1,6G    ./.git/objects/pack/pack-1fafcf28408c80b1d3e3ab3b2d5878e1ae1fad33.pack
523M    ./out/android_arm/lib.unstripped/libchrome.so
273M    ./out/android_arm/toolchain.ninja
210M    ./third_party/instrumented_libraries/binaries/msan-chained-origins-trusty.tgz
188M    ./third_party/instrumented_libraries/binaries/msan-no-origins-trusty.tgz
145M    ./.git/objects/pack/pack-a4ecdc2299e6be44a689642228ef6cab253f01cd.pack
110M    ./out/android_arm/.ninja_deps
83M ./native_client/toolchain/.tars/package_archives/toolchain.tar.bz2/04a77d2e2d6e814a6a5efd66de14142bb4c37c61.tar.bz2
67M ./.git/index
60M ./third_party/llvm-build/Release+Asserts/bin/clang
59M ./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
59M ./third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
56M ./out/android_arm/libchrome.so
55M ./out/android_arm/clang_x86_v8_arm/mksnapshot
53M ./out/android_arm/apks/ChromePublic.apk
52M ./third_party/catapult/tracing/test_data/theverge_trace.json
47M ./third_party/llvm-build/Release+Asserts/bin/lld

I realized that I added and committed the out directory. Edited .gitignore to exclude out and ./third_party/instrumented_libraries/binaries/. Added files and committed. My local history looks like:

last commit (good all large files ignored)

prev commit (bad has `out)

How can I not push the bad commit (with large files)?


Solution

  • Make a new history that doesn't have that commit. Push that. If you've got just the one bad commit you describe, easiest is git reset --soft @~2; git commit; git push; the soft reset only alters your next commit's ancestry, not its content. Since all commits are full snapshots, when you commit again you'll get the same content but the earlier ancestor, and the history won't have the over-sharing bits.