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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:09:03+00:00 2026-05-30T17:09:03+00:00

How do I remove commits that are branched off master ? I have added

  • 0

How do I remove commits that are branched off master?

I have added a large library, along with a very rich commit history (and that predates my code) to a subdirectory via Git subtree. I’d like to retroactively squash that entire history, but still be able to merge in new commits to the library.

I have tried various combinations of git rebase but I never get the expected result [*].

My repository looks something like:

A---B-----------F---G master
               /
  ... C---D---E

and I’d like for it to look something like:

A---B-----------F'--G' master
               /
              E'

or:

A---B-------E'--F'--G' master

[*]:

  • git rebase --onto C E master
  • git checkout F; git rebase --onto C E master
  • 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-30T17:09:04+00:00Added an answer on May 30, 2026 at 5:09 pm
    1. This is history editing. You will end up in something like

      A---B-----------F'---G' master
                     /
                    E'
      
    2. Merging will be a problem after this, because of Git will not be able to find common parents between your history and libraries’s history.

    3. To actually do it you need to

      1. Reset to B (creating tag or branch for G to keep it around)
      2. Perform merge with --no-commit.
      3. Rebase or cherry-pick G here (it will be G’)

      The history will look like

      A---B-----------F'---G'
      

    To make the shallow clone of the library, you need to do something like this (Warning: untested):

    1. Save commits from F (not including) to G (including) to a patch (git format-patch F --stdout > ~/saved_commits.patch)
    2. Reset to B. Ensure there are no branches that are poiting to F, E or G
    3. Remove the remote together with it’s ref namespace git remote rm
    4. Erase reflogs: git reflog expire --expire=now --all
    5. Actually remove things from git: git gc --prune=now. Now you should see the repository shrank.
    6. Re-add the remote for library.
    7. git fetch --depth=10 libraryremote
    8. Repeat the merge (the usual way)
    9. Apply saved commits (git am ~/saved_commits.patch).

    To migrate into submodules solution (the best option probably), you need to rollback to the state before merge and set up submodules, then substitute each merge with changed commit-id for submodule. Unlike for the case of splitting out project directory to submodule I don’t know the automated solution for this (but it can be implemented the similar way).

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

Sidebar

Related Questions

i have commits that are in a remote repository (origin/master) which i want to
I'd like to have a commit message cleanup that will not necessarily remove lines
I have a Git repository that I want to remove all previous commits from.
I had a local branch which was branched off master quite some time ago,
I have a series of commits (20+) that pertain to a particular feature that
I would like to remove selected commit log entries from a linear commit tree,
I accidentally pushed a commit to GitHub. Is it possible to remove this commit?
how remove html table rows after 2nd row? if in table have 5 row,
I need to remove duplicate rows from a fairly large SQL Server table (i.e.
I have two branches that are different enough that rebasing seems to not work

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.