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 8383515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:10:53+00:00 2026-06-09T17:10:53+00:00

I have a very large Git repository which only contains binary files which are

  • 0

I have a very large Git repository which only contains binary files which are changed pretty often. Naturally the Git repository is much larger than the actual files in it. I don’t really care about old history, I only need some of the newer history to be able to revert some wrong changes. So let’s say I want to remove all commits except the last five.

Naturally I want to do this to keep the repository small so the removed commits must be purged completely from the repo.

And I want to do all this non-interactively with a single command (alias) or script. How can I do this?

  • 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-06-09T17:10:54+00:00Added an answer on June 9, 2026 at 5:10 pm

    Here’s an rebase-last-five alias to get you started. It will recreate the current branch so only the most recent five commits are in the history. It’s probably best to make this a script (git-rebase-last-five.sh) that is available in a directory on your PATH; Git will find and use scripts named git-....sh without the need for any special configuration. The script should do more error checking and handling than this simple alias.

    $ git config --global alias.rebase-last-five '!b="$(git branch --no-color | cut -c3-)" ; h="$(git rev-parse $b)" ; echo "Current branch: $b $h" ; c="$(git rev-parse $b~4)" ; echo "Recreating $b branch with initial commit $c ..." ; git checkout --orphan new-start $c ; git commit -C $c ; git rebase --onto new-start $c $b ; git branch -d new-start ; git gc'
    

    CAVEAT EMPTOR: Do heed the warnings about changing history.

    Check the man pages (git help <command> or online) for further information.

    An example usage:

    $ git --version
    git version 1.7.12.rc2.16.g034161a
    $ git log --all --graph --decorate --oneline
    * e4b2337 (HEAD, master) 9
    * e508980 8
    * 01927dd 7
    * 75c0fdb 6
    * 20edb42 5
    * 1260648 4
    * b3d6cc8 3
    * 187a0ef 2
    * e5d09cf 1
    * 07bf1e2 initial
    $ git rebase-last-five 
    Current branch: master e4b2337ef33d446bbb48cbc86b44afc964ba0712
    Recreating master branch with initial commit 20edb42a06ae987463016e7f2c08e9df10fd94a0 ...
    Switched to a new branch 'new-start'
    [new-start (root-commit) 06ed4d5] 5
     1 file changed, 1 insertion(+)
     create mode 100644 A
    First, rewinding head to replay your work on top of it...
    Applying: 6
    Applying: 7
    Applying: 8
    Applying: 9
    Deleted branch new-start (was 06ed4d5).
    Counting objects: 35, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (15/15), done.
    Writing objects: 100% (35/35), done.
    Total 35 (delta 4), reused 0 (delta 0)
    $ git log --all --graph --decorate --oneline
    * a7fb54b (HEAD, master) 9
    * 413e5b0 8
    * 638a1ae 7
    * 9949c28 6
    * 06ed4d5 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very large files (more than 10Gb). I need only some lines from
I have a very large (~6GB) SVN repository, for which I've written a batch
I have very large datasets that are stored in binary files on the hard
I have a very large XML file which has like 40000 data, and when
I have a very large program which I have been compiling under visual studio
I converted a very large svn repository to a git repository with git svn
I have very large website which uses a lot of cookies. There are approx.
I need help with regular expression. I have very large collection of text files
I have a git repo with some very large binaries in it. I no
I am looking for opinions of how to handle large binary files on which

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.