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

Cleaning the .git directory with gc

From
HRHaakon Riiser <haakon.riiser@fys.uio.no>
Date
Apr 23, 2008, 23:13 UTC
Message-ID
<20080423231359.GA30913@fox>

I've recently started using git, and while experimenting with git commit --amend, I noticed that git gc does not do what I expected. Example:

  $ mkdir foo && cd foo
  $ git init
  $ dd if=/dev/urandom bs=1k count=1000 of=rand.dat
  $ git add .
  $ git commit -a -m 'first rev'
  $ du -s .git
  1100    .git
1 MB file checked in, 1 MB repository.  So far, so good.
  $ dd if=/dev/urandom bs=1k count=1000 of=rand.dat
  $ git commit -a -m 'replaced first rev' --amend
  $ du -s .git
  2120    .git

At this point, I expected the --amend command to notice that the amended commit contains a replacement for the old file, and thus that the repository didn't grow. I then figured that if --amend doesn't do that by itself, git gc surely will:

  $ git gc
  $ du -s .git
  2104    .git

So, why doesn't gc remove the data from the first commit? Is it still accessible, even though the log doesn't show it?

Is it possible to actually replace the commit, i.e., to make it exactly like the first commit never happend at all? (Without modifying the repository by hand.)

-- 
 Haakon
Next: Russ Dill
Message 1 of 6 in “Cleaning the .git directory with gc”
  1. Haakon RiiserApr 23, 2008
  2. Russ DillApr 24, 2008
  3. David TweedApr 24, 2008
  4. Shawn O. PearceApr 24, 2008
  5. Shawn O. PearceApr 24, 2008
  6. Haakon RiiserApr 24, 2008

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.