Git: show total file size difference between two commits?

后端 未结 5 476
心在旅途
心在旅途 2020-12-04 08:05

Is it possible to show the total file size difference between two commits? Something like:

$ git file-size-diff 7f3219 bad418 # I wish this worked :)
-1234 b         


        
5条回答
  •  鱼传尺愫
    2020-12-04 08:54

    A comment to the script: git-file-size-diff, suggested by patthoyts. The script is very useful, however, I have found two issues:

    1. When someone change permissions on the file, git returns a another type in the case statement:

      T) echo >&2 "Skipping change of type"
      continue ;;
      
    2. If a sha-1 value doesn't exist anymore (for some reason), the script crashes. You need to validate the sha before getting the file size:

      $(git cat-file -e $D) if [ "$?" = 1 ]; then continue; fi

    The complete case statement will then look like this:

    case $M in
          M) $(git cat-file -e $D)
             if [ "$?" = 1 ]; then continue; fi
             $(git cat-file -e $C)
             if [ "$?" = 1 ]; then continue; fi
             bytes=$(( $(git cat-file -s $D) - $(git cat-file -s $C) )) ;;
          A) $(git cat-file -e $D)
             if [ "$?" = 1 ]; then continue; fi
             bytes=$(git cat-file -s $D) ;;
          D) $(git cat-file -e $C)
             if [ "$?" = 1 ]; then continue; fi
             bytes=-$(git cat-file -s $C) ;;
          T) echo >&2 "Skipping change of type"
             continue ;;
          *)
            echo >&2 warning: unhandled mode $M in \"$A $B $C $D $M $P\"
            continue
            ;;
        esac
    

提交回复
热议问题