13

I have a series of commits that I'd want to push to my remote repository, but I'm using an internet connection that's data capped and I'd like to know how big the commit is to decide whether to push it now or later when I'm on a connection with a larger data cap.

You can see how big a push is when you're in the middle of it, but is there a way to figure out how big it is before actually pushing?

1 Answers1

14

It's kind of possible. Via bash, and assuming origin/master is your target branch:

$ echo $(git merge-base HEAD origin/master)..HEAD | git pack-objects --revs --thin --stdout --all-progress-implied > packfile

Inspecting the size of the resulting packfile will give you an idea of how much data you need to send to make the remote up-to-date.

I took this approach from an older answer, when I was tooling around trying to figure out my upload pack size. It's a bit of a hack, as you need to generate a packfile -- in theory, once you know the range of commits that have changed locally and remotely, you can just ask git for the names of those objects (a recursive problem, as objects may refer to other objects) and tally the sizes of those objects.

(Then again, generating the pack file also packs those objects -- just like git push would do -- so the size is more representative of what would be sent.)

If you have other developers working on the branch you wish to push to, then any estimate is moot, as you will likely have to run git fetch before pushing to the remote, which means transferring an unknown amount of data!

Community
  • 1
  • 1
Blair Holloway
  • 15,969
  • 2
  • 29
  • 28
  • This worked great, thanks. Noted on the collaboration aspect: in this case, I'm only worried about the upload size and the user story I provided was contrived. –  Feb 21 '11 at 06:01
  • 1
    or just get the size in bytes right away: `echo $(git merge-base HEAD origin/master)..HEAD | git pack-objects --revs --thin --stdout --all-progress-implied -q | wc -c` – kch Sep 06 '12 at 05:13