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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:35:31+00:00 2026-05-22T01:35:31+00:00

Suppose I have such tree: … — a — b — c — d

  • 0

Suppose I have such tree:

... -- a -- b -- c -- d -- ...
             \
              e -- a -- k

and I want it become just

... -- a -- b -- c -- d -- ...

I know how to attach branch name to “e”. I know that what I’m going to do will change history, and this is bad. Also I guess I need to use something like rebase or filter-branch. But how exactly – I’m lost.

Ok. Situation is following: I have rather big tree now (like this)

                 s -- p -- r   
                /
a -- b -- c -- d -- e --- g -- w
           \               \
            t -- p -- l     y -- k

but in my one of first commits (like to “b” for ex.) I added binary files, which makes whole repo very heavy. So I decided to take them away. I did it with filter-branch. And Now I have 2 long branches of commits identical to each other starting from second commit.

                 s -- p -- r   
                /
a -- b -- c -- d -- e --- g -- w
      \    \               \
       \    t -- p -- l     y -- k
        \
         \             s'-- p'-- r'  
          \           /
           b'-- c'-- d'-- e'--- g'-- w'
                 \               \
                  t'-- p'-- l'    y'-- k'

where b’ is commit without binary file in it. So I can’t do merge. I don’t want this whole tree to be in history duplicated so.

  • 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-22T01:35:32+00:00Added an answer on May 22, 2026 at 1:35 am

    After importing a Subversion repository with multiple years of history, I ran into a similar problem with bloat from lots of binary assets. In git: shrinking Subversion import, I describe trimming my git repo from 4.5 GiB to around 100 MiB.

    Assuming you want to delete from all commits the files removed in “Delete media files” (6fe87d), you can adapt the approach from my blog post to your repo:

    $ git filter-branch -d /dev/shm/git --index-filter \
      "git rm --cached -f --ignore-unmatch media/Optika.1.3.?.*; \
       git rm --cached -f --ignore-unmatch media/lens.svg; \
       git rm --cached -f --ignore-unmatch media/lens_simulation.swf; \
       git rm --cached -f --ignore-unmatch media/v.html" \
      --tag-name-filter cat --prune-empty -- --all

    Your github repo doesn’t have any tags, but I include a tag-name filter in case you have private tags.

    The git filter-branch documentation covers the --prune-empty option.

    --prune-empty
    Some kinds of filters will generate empty commits that leave the tree untouched. This switch allows git-filter-branch to ignore such commits …

    Using this option means your rewritten history will not contain a “Delete media files” commit because it no longer affects the tree. The media files are never created in the new history.

    At this point, you’ll see duplication in your repository due to another documented behavior.

    The original refs, if different from the rewritten ones, will be stored in the namespace refs/original/.

    If you’re happy with the newly rewritten history, then delete the backup copies.

    $ git for-each-ref --format="%(refname)" refs/original/ | \
      xargs -n 1 git update-ref -d

    Git is vigilant about protecting your work, so even after all this intentional rewriting and deleting the reflog is keeping the old commits alive. Purge them with a sequence of two commands:

    $ git reflog expire --verbose --expire=0 --all
    $ git gc --prune=0

    Now your local repository is ready, but you need to push the updates to GitHub. You could do them one at a time. For a local branch, say master, you’d run

    $ git push -f origin master

    Say you don’t have a local issue5 branch any more. Your clone still has a ref called origin/issue5 that tracks where it is in your GitHub repository. Running git filter-branch modifies all the origin refs too, so you can update GitHub without a branch.

    $ git push -f origin origin/issue5:issue5

    If all your local branches match their respective commits on the GitHub side (i.e., no unpushed commits), then you can perform a bulk update.

    $ git for-each-ref --format="%(refname)" refs/remotes/origin/ | \
      grep -v 'HEAD$' | perl -pe 's,^refs/remotes/origin/,,' | \
      xargs -n 1 -I '{}' git push -f origin 'refs/remotes/origin/{}:{}'

    The output of the first stage is a list of refnames:

    $ git for-each-ref --format="%(refname)" refs/remotes/origin/
    refs/remotes/origin/HEAD
    refs/remotes/origin/issue2
    refs/remotes/origin/issue3
    refs/remotes/origin/issue5
    refs/remotes/origin/master
    refs/remotes/origin/section_merge
    refs/remotes/origin/side-media-icons
    refs/remotes/origin/side-pane-splitter
    refs/remotes/origin/side-popup
    refs/remotes/origin/v2

    We don’t want the HEAD pseudo-ref and remove it with grep -v. For the rest, we use Perl to strip off the refs/remotes/origin/ prefix and for each one run a command of the form

    $ git push -f origin refs/remotes/origin/BRANCH:BRANCH
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have an IEnumerable such as a List(TValue) and I want to keep
Suppose I have code that maintains a parent/children structure. In such a structure I
Background: Suppose I have a powershell function that understands and interprets small_commands such as:
Suppose you have two static libraries A and B such that A references methods
Suppose I have a system where I have metadata such as: table: ====== key
Suppose I have a structure in C or C++, such as: struct ConfigurableElement {
Suppose I'm implementing an MVP pattern and I have a view interface as such:
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
Suppose I have such chunk of a sentence: (NP (NP (DT A) (JJ single)
Let's suppose I have such helper methods used by some object. private int MatchRegex(string

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.