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

Re: git-add fails after file type change

From
Junio C Hamano <junkio@cox.net>
Date
Dec 17, 2006, 00:46 UTC
Message-ID
<7vvekb73jh.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<45848CF8.4000704@midwinter.com>
Steven Grimm <koreth@midwinter.com> writes:
Show 8 quoted lines
> A Large Angry SCM wrote:
>> Did you try "git-update-index --replace dir"?
>
> Turns out that doesn't work. It gives me the same error I get without
> the --replace option:
>
> error: dir: cannot add to the index - missing --add option?
> fatal: Unable to process file dir
"update-index --replace --add" would be the way.
        $ git ls-files -s
        100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0	1/2
        100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0	3
        $ ls -F
        ./  ../  1/  3	.git/
There is file 1/2 in directory 1.
        $ mv 1 tmp ; mv 3 1 ; mv tmp 3
        $ ls -F
        ./  ../  1  3/	.git/
I just swapped them.
        $ git update-index --replace --add 1
        $ git ls-files -s
        100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0	1
        100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0	3

You are allowing update-index to 'add' things so you would need to say --add regardless of --replace (--replace is only to allow removal of conflicting entries while adding). In the hindsight, we could have implied --add with --replace, but that is the way it is, and update-index is not a Porcelain so there is not much point fixing it now.

But I think you helped me to spot a bug ;-).
        $ git update-index --replace --add 3/2
        $ git ls-files -s
        100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0	1
	100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0	3
        100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0	3/2

The entry '3' should have been removed when we did --replace. This index cannot be written out as a tree:

	$ git write-tree
        You have both 3 and 3/2
        fatal: git-write-tree: error building trees
Currently we need to remove '3' by hand X-<.
        $ git update-index --remove 3
        $ git ls-files -s
        100644 00750edc07d6415dcc07ae0351e9397b0222b7ba 0	1
        100644 fa457baf8abbf5dd3bb4cbfab0c5a4cf0523d7f8 0	3/2
        $ git write-tree
        77be0dd800d74913a90662e35215ee648815fc17
Previous: Steven GrimmNext: Junio C Hamano
Message 8 of 11 in “git-add fails after file type change”
  1. Steven GrimmDec 16, 2006
  2. Jakub NarebskiDec 16, 2006
  3. Steven GrimmDec 16, 2006
  4. A Large Angry SCMDec 16, 2006
  5. Junio C HamanoDec 16, 2006
  6. Steven GrimmDec 16, 2006
  7. Steven GrimmDec 17, 2006
  8. Junio C HamanoDec 17, 2006
  9. Junio C HamanoDec 17, 2006
  10. git-add: remove conflicting entry when adding.Junio C Hamano, Dec 17, 2006
  11. Junio C HamanoDec 16, 2006

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.