Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:56:47+00:00 2026-05-28T22:56:47+00:00

I’m currently thinking of changing my VCS (from subversion) to git. Is it possible

  • 0

I’m currently thinking of changing my VCS (from subversion) to git. Is it possible to limit the file size within a commit in a git repository? For e. g. subversion there is a hook: http://www.davidgrant.ca/limit_size_of_subversion_commits_with_this_hook

From my experience people, especially those who are inexperienced, sometimes tend to commit files which should not go into a VCS (e. g. big file system images).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:56:49+00:00Added an answer on May 28, 2026 at 10:56 pm

    As I was struggling with it for a while, even with the description, and I think this is relevant for others too, I thought I’d post an implementation of how what J16 SDiZ described could be implemented.

    So, my take on the server-side update hook preventing too big files to be pushed:

    #!/bin/bash
    
    # Script to limit the size of a push to git repository.
    # Git repo has issues with big pushes, and we shouldn't have a real need for those
    #
    # eis/02.02.2012
    
    # --- Safety check, should not be run from command line
    if [ -z "$GIT_DIR" ]; then
            echo "Don't run this script from the command line." >&2
            echo " (if you want, you could supply GIT_DIR then run" >&2
            echo "  $0 <ref> <oldrev> <newrev>)" >&2
            exit 1
    fi
    
    # Test that tab replacement works, issue in some Solaris envs at least
    testvariable=`echo -e "\t" | sed 's/\s//'`
    if [ "$testvariable" != "" ]; then
            echo "Environment check failed - please contact git hosting." >&2
            exit 1
    fi
    
    
    # File size limit is meant to be configured through 'hooks.filesizelimit' setting
    filesizelimit=$(git config hooks.filesizelimit)
    
    # If we haven't configured a file size limit, use default value of about 100M
    if [ -z "$filesizelimit" ]; then
            filesizelimit=100000000
    fi
    
    # Reference to incoming checkin can be found at $3
    refname=$3
    
    # With this command, we can find information about the file coming in that has biggest size
    # We also normalize the line for excess whitespace
    biggest_checkin_normalized=$(git ls-tree --full-tree -r -l $refname | sort -k 4 -n -r | head -1 | sed 's/^ *//;s/ *$//;s/\s\{1,\}/ /g' )
    
    # Based on that, we can find what we are interested about
    filesize=`echo $biggest_checkin_normalized | cut -d ' ' -f4,4`
    
    # Actual comparison
    # To cancel a push, we exit with status code 1
    # It is also a good idea to print out some info about the cause of rejection
    if [ $filesize -gt $filesizelimit ]; then
    
            # To be more user-friendly, we also look up the name of the offending file
            filename=`echo $biggest_checkin_normalized | cut -d ' ' -f5,5`
    
            echo "Error: Too large push attempted." >&2
            echo  >&2
            echo "File size limit is $filesizelimit, and you tried to push file named $filename of size $filesize." >&2
            echo "Contact configuration team if you really need to do this." >&2
            exit 1
    fi
    
    exit 0
    

    Note that it’s been commented that this code only checks the latest commit, so this code would need to be tweaked to iterate commits between $2 and $3 and do the check to all of them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.