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

Rewriting history with git-filter-branch and leaking objects (?)

From
Mike Hommey <mh@glandium.org>
Date
Aug 17, 2007, 17:18 UTC
Message-ID
<20070817171851.GB13891@glandium.org>
Hi,

I've been playing with git-filter-branch, and was wondering how objects from the original branch are supposed to be removed.

It looks like removing the refs/original/* refs is not enough.

And it also looks like when all references seem to be removed, git-prune doesn't fully do its job...

See the following transcript:
$ git init
Initialized empty Git repository in .git/
$ echo a > a ; echo b > b
$ git add a b
$ git commit -m "add a b"
Created initial commit b8875b1: add a b
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 a
 create mode 100644 b
$ echo a >> a
$ git commit -a -m "update a"
Created commit fd97ed9: update a
 1 files changed, 1 insertions(+), 0 deletions(-)
$ git-filter-branch --index-filter 'git-update-index --remove b' HEAD
Rewrite fd97ed9a2fef62eca824361fb62269e3c1fc0fb8 (2/2)
Ref 'refs/heads/master' was rewritten

These refs were rewritten: fatal: Not a git repository: '/tmp/test/.git-rewrite/t/../../.git'

(This is a message that happens when GIT_DIR is not set, I guess the patches that were sent a few days ago on the list fix this issue)

$ git-cat-file commit b8875b1 tree 3683f870be446c7cc05ffaef9fa06415276e1828 author Mike Hommey <mh@namakemono.glandium.org> 1187369087 +0200 committer Mike Hommey <mh@namakemono.glandium.org> 1187369087 +0200

add a b

(not a surprise, since we still have the refs/original/refs/heads/master ref)

$ git-update-ref -d refs/original/refs/heads/master fd97ed9 $ git-cat-file commit b8875b1 tree 3683f870be446c7cc05ffaef9fa06415276e1828 author Mike Hommey <mh@namakemono.glandium.org> 1187369087 +0200 committer Mike Hommey <mh@namakemono.glandium.org> 1187369087 +0200

add a b $ git fsck

(okay, so it is still here, and obviously still referenced ; it appears to be referenced in .git/logs/...)

$ rm .git/logs/refs/heads/master $ rm .git/logs/HEAD $ git fsck dangling commit fd97ed9a2fef62eca824361fb62269e3c1fc0fb8

(finally ! So here is a first question: is there a proper way to clean this out ? rm of the logs sounds brutal...)

$ git-prune -n 3683f870be446c7cc05ffaef9fa06415276e1828 tree b8875b1095616c1e7e8f8ffce8ebc172059367ea commit fd97ed9a2fef62eca824361fb62269e3c1fc0fb8 commit $ git-cat-file commit fd97ed9a2fef62eca824361fb62269e3c1fc0fb8 tree c1f89248e4b6e47a4529d50d37b0840a14d2efb0 parent b8875b1095616c1e7e8f8ffce8ebc172059367ea author Mike Hommey <mh@namakemono.glandium.org> 1187369110 +0200 committer Mike Hommey <mh@namakemono.glandium.org> 1187369110 +0200

update a

(Why doesn't prune -n tell me it would remove c1f89248e4b6e47a4529d50d37b0840a14d2efb0, which it should, AFAIK ?)

Mike
Next: David Kastrup
Message 1 of 7 in “Rewriting history with git-filter-branch and leaking objects (?)”
  1. Mike HommeyAug 17, 2007
  2. David KastrupAug 17, 2007
  3. Mike HommeyAug 17, 2007
  4. Sam VilainAug 19, 2007
  5. Junio C HamanoAug 17, 2007
  6. Mike HommeyAug 17, 2007
  7. Mike HommeyAug 19, 2007

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.