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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:29:17+00:00 2026-05-31T13:29:17+00:00

Possible Duplicate: Completely remove (old) git commits from history git is very useful for

  • 0

Possible Duplicate:
Completely remove (old) git commits from history

git is very useful for nightly snapshots of client web sites. Knowing everything (php + mysqldump + user file uploads) is in a git repository provides great peace of mind.

Due to the large size of some of the sites, I am wondering if anyone is aware a moderately easy way to remove (for example) all commits older than 30 days?

  • 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-31T13:29:17+00:00Added an answer on May 31, 2026 at 1:29 pm

    Indeed, you actually can do this. It’s a bit tricky. Here’s an example…

    $ cd /tmp
    $ mkdir rmcommits
    $ cd rmcommits
    $ git init
    Initialized empty Git repository in /tmp/rmcommits/.git/
    $ cp /tmp/example/xy.c .
    $ git add xy.c
    $ git commit -m 'initial commit'
    [master (root-commit) 8d5b88c] initial commit
     1 files changed, 273 insertions(+), 0 deletions(-)
     create mode 100644 xy.c
    $ echo 'more stuff' > morestuff.txt
    $ git add morestuff.txt; git commit -m 'add some stuff'
    [master f971ae5] add some stuff
     1 files changed, 1 insertions(+), 0 deletions(-)
     create mode 100644 morestuff.txt
    $ echo 'and still more' >> morestuff.txt 
    $ git add morestuff.txt; git commit -m 'add more stuff'
    [master bea9192] add more stuff
     1 files changed, 1 insertions(+), 0 deletions(-)
    

    Now I pick out the place where I want “history to end” (for branch master, aka HEAD):

    $ git rev-parse HEAD^
    f971ae5b4225aca364223a44be8be84268385ff3
    

    This is the last commit I will keep.

    $ git filter-branch --parent-filter 'test $GIT_COMMIT == f971ae5b4225aca364223a44be8be84268385ff3 && echo "" || cat' HEAD
    Rewrite bea9192a53a5aeb7532aa1e174f7f642363396de (3/3)
    Ref 'refs/heads/master' was rewritten
    $ git log --pretty=oneline
    65a246b8320382a64550d2c4b650c942d7bfba70 add more stuff
    7892ab45aa33cd5ebdc3090ce2622081059fdd79 add some stuff
    

    (Explanation: git filter-branch basically runs over all the commits in the branch, in this case master because HEAD is currently ref: refs/heads/master, and with –parent-filter, you can rewrite the parent(s) of each commit. When we find the target commit, before which we want history to cease, we echo nothing—you don’t need the empty string, that’s my old habit from when echo with no arguments did nothing—otherwise we use “cat” to copy the existing -p arguments, as per the filter-branch manual. This makes the new commit, based off the one we tested for, have no parents, i.e., it’s now an initial commit — the root of the branch. This is unusual in a git repo, as we now have two root commits, one on the new master and one on the old, saved master as noted below.)

    Note that the older commit tree is still in the repo in its entirety, under the saved name that git filter-branch uses:

    $ git log original/refs/heads/master --pretty=oneline
    bea9192a53a5aeb7532aa1e174f7f642363396de add more stuff
    f971ae5b4225aca364223a44be8be84268385ff3 add some stuff
    8d5b88c468f75750d5a01ab40bfae160c654ac66 initial commit
    

    You have to delete that reference (and clean out the reflog) and do a “git gc” before the rewritten commits (and any unreferenced trees, blobs, etc) really go away:

    $ git update-ref -d refs/original/refs/heads/master
    $ git reflog expire --expire=now --all
    $ git gc --prune=now
    $ git fsck --unreachable
    $
    

    That last line shows that they’re really gone.

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

Sidebar

Related Questions

Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Possible Duplicate: How do I make a WiX installer with a completely self-contained .NET
Possible Duplicate: How do I read a resource file from a Java jar file?
Possible Duplicate: Converting ereg expressions to preg I'm trying to fix some old code
Possible Duplicate: C++ singleton vs completely static object Hi, why should I prefer a
Possible Duplicate: Array slicing in Ruby: looking for explanation for illogical behaviour (taken from
Possible Duplicate: How do I remove code duplication between similar const and non-const member
Possible Duplicate: Is there a way to have content from an IFRAME overflow onto
Possible Duplicate: Working with large numbers in PHP. I run a completely useless Facebook

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.