Find total file size with unlimited or raw file in git

I have a big, awful bunch of code, and I'm setting it up for version control.

I need a command that I can run on Linux to give me the total size of files to be committed and pushed if I run git add -A && git commit -am 'initial commit'

A general size is required, and folders may also be convenient.

Then I will use this to create my ignores, to get the repo to a realistic size, before I raise it.

+9
git linux bash
source share
4 answers

I think I answered my question:

 for f in `git status --porcelain | sed 's#^...##'`; do du -cs $f | head -n 1; done | sort -nr; echo "TOTAL:"; du -cs . 

However, I am open to any best ideas or useful tricks. My current output is 13 GB :)


The above command is basically there, it gives me the complete line by line from the git state, but it does not give me the total. I am currently getting the total number of all files at the end, which is incorrect. I tried using bc but couldn't get it to work

+8
source share

I adapted the edmondscommerce answer by adding a simple awk statement that sums the output of the for loop and prints the sum (divided by 1024 * 1024 to convert to Mb)

 for f in `git status --porcelain | sed 's#^...##'`; do du -cs $f | head -n 1; done | sort -nr | awk ' {tot = tot+$1; print } END{ printf("%.2fMb\n",tot/(1024*1024)) }' 

Note that --porcelain prints paths relative to the root of the git repository. So, if you do this in a subdirectory, du will not be able to find the files.

(whoppa; my first answer in SoF is whether strength can be with him)

+3
source share

Since you just add everything, I see no reason to go through Git. Just use regular Unix tools: du , find , & c.

0
source share

I used a modified version of this because I had files with spaces that caused it to crash. I was also not sure about the sizes and removed the useless head :

 git status --porcelain | sed 's/^...//;s/^"//;s/"$//' | while read path; do du -bs "$path" ; done | sort -n | awk ' {tot = tot+$1; print } END { printf("%.2fMB\n",tot/(1024*1024)) }' 

I prefer to use while as it's a little safer than for : it can still do nasty things with files that have newlines in them, so I wanted to pass null -separate files so far to be able to extract status information, but I could not find a good way to do this.

0
source share

All Articles