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

Using ‘git replace’ to replace blobs

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 7, 2010, 01:10 UTC
Message-ID
<20100207011056.GA15307@progeny.tock>

I think it is a known problem that ‘git replace’ cannot be used safely to replace blobs used in the currently checked out commit. The man page says:

	Comparing blobs or trees that have been replaced with
	those that replace them will not work properly.
Indeed, in practice it produces problems. [1]

I would like to start to fix this. But the correct semantics are not obvious to me:

 - When writing a tree from an index that includes replaced blobs,
   should the result use the original blobs or the replaced ones?
 - When reading a tree that includes replaced blobs, should the
   resulting cache entries use the original blobs or the replaced
   ones?

My hunch is to say both should use the replaced blobs. This way, replacing a blob in a checked-out index would behave in a more intuitive way, and git filter-branch would make permanent any substitutions requested through replaced blob entries.

I have not thought it through completely, though.

Thoughts? Jonathan

[1] For example,
 git init repo
 cd repo
 echo first > 1.txt
 echo second > 2.txt
 git add 1.txt 2.txt
 git commit -m demonstration
 git show --raw
 git ls-tree HEAD | awk '
	NR == 1 { first = $3 }
	NR == 2 { system("git replace " first " " $3) }
 '
 git status
 rm *
 git checkout -f
 git status
which one would expect to result in a clean tree, produces
 Initialized empty Git repository in /tmp/repo/.git/
 [master (root-commit) 998cc27] demonstration
  2 files changed, 2 insertions(+), 0 deletions(-)
  create mode 100644 1.txt
  create mode 100644 2.txt
 commit 998cc270986f68450f00bda5e5db62f31367ff96
 Author: Jonathan Nieder <jrnieder@gmail.com>
 Date:   Sat Feb 6 18:48:50 2010 -0600
     demonstration
 :000000 100644 0000000... 9c59e24... A  1.txt
 :000000 100644 0000000... e019be0... A  2.txt
 # On branch master
 nothing to commit (working directory clean)
 # On branch master
 # Changed but not updated:
 #   (use "git add <file>..." to update what will be committed)
 #   (use "git checkout -- <file>..." to discard changes in working
 #   directory)
 #
 #       modified:   1.txt
 #
 no changes added to commit (use "git add" and/or "git commit -a")
Next: Christian Couder
Message 1 of 2 in “Using ‘git replace’ to replace blobs”
  1. Jonathan NiederFeb 7, 2010
  2. Christian CouderFeb 7, 2010

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.