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

  • Home
  • SEARCH
  • 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 8140213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:05:13+00:00 2026-06-06T12:05:13+00:00

This question is about rewriting git history. Six months ago I decided to make

  • 0

This question is about rewriting git history. Six months ago I decided to make changes over an existing subfolder of my repository, and now I’ve changed my mind and want to undo that and all the associated history. Note, I want changes outside that subfolder should be left as is.

So, specifically, I am trying to remove the history of all the changes made within one of the subfolders of the repo, from a certain date onwards.

The end result I am hoping for should look like no edits/adds/deletes were ever made in the subfolder after that date.

Looking at the the answer to Remove file from git repository (history), and also http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository, the closest I’ve got is this:

git filter-branch --index-filter 'git rm -r -f --cached --ignore-unmatch TheFolderToRemove' --prune-empty --all xxxxxx..HEAD 
git reset --hard
git remote rm origin
rm -r .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive
git prune

This removes all the files in the subfolder.

Can someone please show me how to modify this so that it just removes the changes applied within the folder? Many thanks

  • 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-06T12:05:17+00:00Added an answer on June 6, 2026 at 12:05 pm

    Running the filter-branch with git rm --cached tells git to remove the directory and stage that removal! It only did what you told it to do.

    If you still have the original objects: (i.e. you didn’t actually run gc and prune)

    You want to use git reset to unstage changes to that directory from the index, not remove the directory itself:

    $ git filter-branch --index-filter 'git reset -q xxxxxx TheFolderToRemove' \
    >     --prune-empty -- --all xxxxxx..HEAD
    

    where xxxxxx is the commit with state you want the folder to be in.

    If you do not still have the original objects: (i.e. you pruned the old tree from your repository)

    Checkout the commit in which the folder is shown as removed (I believe it should be the commit after xxxxxx), undo the removal, amend the commit, and rebase the rest of history on top:

    $ git checkout -b temp <commit_after_xxxxxx>
    $ git checkout HEAD^ <removed_folder>
    $ git commit --amend
    [temp abcdef1] <message>
    

    Then, if master is your only branch:

    $ git rebase --preserve-merges temp master
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I originally asked this question about an hour ago but only recently realized
Follow up to this question about GNU make : I've got a directory, flac
A few days ago I asked this question about jquery ajax function invoking action
I asked this question about rewriting old ugly links into seo friendly ones. I
Someone asked this question about a year ago but I was unable to turn
This question about Timers for windows services got me thinking: Say I have (and
Followed this question about delayed_job and monit Its working on my development machine. But
I've this question about pass some instances by ref or not: here is my
I have seen this question about deploying to WebSphere using the WAS ant tasks.
This is sort of the Java analogue of this question about C# . Suppose

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.