Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know the percentage of git add . that is already processed?

I'm adding multiple and large files into a repo.

git add .

It is taking a lot of time. Is there any way I can display the progress bar, so that I can know how much of the files is already added to the repo?

like image 843
mrk Avatar asked Jul 30 '18 08:07

mrk


2 Answers

No progress-bar, but, at least, you will get some feedback and see which files have already been added:

 git add --verbose .
like image 80
sergej Avatar answered Sep 20 '22 11:09

sergej


Here is a one-liner, that calculates the progress percentage every second:

git add --verbose . > ../progress.txt & percent=0; while [[ $percent -le 99 && $percent -ge 0 ]]; do num1=$(cat ../progress.txt | wc -l); num2=$(find . -type f -not -path "./.git/*" | wc -l); percent=$((num1*100 / (num2 - 3) )); echo $percent"%"; sleep 1; done; echo "DONE"; sleep 1; rm ../progress.txt
  • While the progress less than 100%
  • Count the lines what git add generated ( num1 )
  • Count the all files in the folder except .git/* ( num2 )
  • Calculate percentage based on these numbers ( num1*100 / num2 )
    • We should subtract 3 from num2, because the find command echoes more lines than expected
  • the script generates a temporary progress.txt file, but it removes at the end

Example output:

12%
25%
50%
50%
75%
75%
100%
like image 27
hlorand Avatar answered Sep 21 '22 11:09

hlorand