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

Re: A puzzle: reset --hard and hard links

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 24, 2022, 21:19 UTC
Message-ID
<xmqqfspc3k8k.fsf@gitster.g>
In-Reply-To
<CABrKpmB7UEGzLCiNHQtY5-Dt16jLkpcpBEx3o8y9OBGZ418keA@mail.gmail.com>
Michael Herrmann <michael@herrmann.io> writes:
Show 11 quoted lines
>> It is merely because you helped Git to realize
>
> I don't want to "help Git realize". I'm sorry but in my opinion `git
> status` should not have any effects on other commands. I don't
> understand how you can argue that calling `git status` is a valid fix
> to "help Git".
>
>> With another step 1.5 "append a line to the file in question", git
>> should severe the link,
>
> I don't want to sever the hard link. I want to avoid that it gets severed.

Sorry, if that is the case, what you want is not a version control, and it is certainly not Git. You want something else.

Think about this scenario.
    $ rm -fr one && git init one && cd one
    $ echo 0 >a; echo 0 >b; git add a b; git commit -m zero
We have two files, a and b, each of which has "0" in it.
    $ echo 1 >b; git add b; git commit -m one
Now they have "0" and "1" respectively.
    $ echo 2 >a; echo 2 >b; git commit -a -m two
    $ ln -f a b
    $ git diff
    $ git diff HEAD

Now they have "2". Since they have identical contents, "diff" would report no difference relative to the index or HEAD, even after we manually break the working tree by making one of them a hardlink to the other.

Now, what should this command do?
    $ git reset --hard HEAD^

What the user is asking is (1) to move the branch to point at the previous commit, which had 0 and 1 in a and b respectively, and (2) to make sure that the index and the working tree contents match what is recorded in the commit.

So for Git to be a usefully correct version control system, it is essential to make sure what it writes out would not affect any path other than the one it is writing out. When it writes "0" to "a", it MUST break the hardlink from elsewhere that points at "a" before it does so. Otherwise, the "0" it writes into "a" will also be seen elsewhere, which is not what the updated HEAD (i.e. commit "one") wants to see. The same for "b" when it is updated from "2" to "1" when this happens.

Previous: Michael HerrmannNext: rsbecker@nexbridge.com
Message 10 of 18 in “A puzzle: reset --hard and hard links”
  1. Michael HerrmannJan 19, 2022
  2. brian m. carlsonJan 19, 2022
  3. Junio C HamanoJan 19, 2022
  4. Michael HerrmannJan 20, 2022
  5. brian m. carlsonJan 20, 2022
  6. Michael HerrmannJan 21, 2022
  7. Michael HerrmannJan 24, 2022
  8. Junio C HamanoJan 24, 2022
  9. Michael HerrmannJan 24, 2022
  10. Junio C HamanoJan 24, 2022
  11. rsbecker@nexbridge.comJan 24, 2022
  12. Michael HerrmannJan 24, 2022
  13. Andreas SchwabJan 25, 2022
  14. Ævar Arnfjörð BjarmasonJan 25, 2022
  15. Andreas SchwabJan 25, 2022
  16. Michael HerrmannJan 25, 2022
  17. brian m. carlsonJan 26, 2022
  18. Junio C HamanoJan 26, 2022

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.