git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to remove a git subtree and its history?

From
Avery Pennarun <apenwarr@gmail.com>
Date
Mar 23, 2011, 17:09 UTC
Message-ID
<AANLkTi=WX+jD-Vz0wtorHgMBQLQ4=ycHVzZeUt8goxyL@mail.gmail.com>
In-Reply-To
<4D89B6F4.2050209@jku.at>
On Wed, Mar 23, 2011 at 2:01 AM, Robert Pollak <robert.pollak@jku.at> wrote:
Show 11 quoted lines
> Am 22.03.2011 21:44, schrieb Avery Pennarun:
>> I've never tried to do this since
>> the history rewrite you'd be doing in this case would completely
>> invalidate all your old history: by removing the subtree in all past
>> revisions, you make all those past revisions unbuildable, which seems
>> like missing the point of version control.  Nevertheless, I'm sure you
>> could make it happen if you wanted; you can do pretty much anything
>> you want by filtering git history.
>
> I see. As quite a git newbie I hoped you had done this already and could
> help me with the necessary git filter-branch command line.

I don't really have time to decode it all for you, but there are basically two things you need to do here:

1) filter out the subtree merge commits
2) filter out the actual files.

You didn't really say which part of git-filter-branch *didn't* work for you. I'm assuming you were successful at #2, since that part comes straight out of the filter-branch documentation, and you ended up with some leftover git history (ie. log entries from the parent project) that you don't want to see.

The easiest way I know to remove commits from the middle of history (other than rebase, but that's too painful when there are merges) is to use grafts: https://git.wiki.kernel.org/index.php/GraftPoint

Or maybe 'git replace' is easier than grafts nowadays.

After replacing the offending merge commits, run filter-branch one more time to make the changes permanent.

Show 7 quoted lines
>>> (Be free to CC git@vger.kernel.org if you reply, if you think that's
>>> appropriate for archiving the info.)
>>
>> I don't understand why you didn't cc: the git list yourself then.  But okay :)
>
> I was not sure whether discussion of git-subtree belongs there, since it
> is not part of git (yet?).

The git list seems to be used for discussion of git side projects sometimes. As it happens, I'm not subscribed to the list anymore (nothing personal; I just can't handle the volume right now), so it's important to leave me on the cc: list though if you want me to see it.

Have fun,
Avery
Previous: Robert Pollak
Message 3 of 3 in “Re: How to remove a git subtree and its history?”
  1. Avery PennarunMar 22, 2011
  2. Robert PollakMar 23, 2011
  3. Avery PennarunMar 23, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.