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 19, 2022, 22:37 UTC
Message-ID
<xmqqilufl5cv.fsf@gitster.g>
In-Reply-To
<YeiOoAcM7TMK2pgz@camp.crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> Whether it happens in this particular case probably depends on what data
> is in the index and whether it's considered stale, since if the file is
> out of date, I believe a git reset --hard will replace it rather than
> try to determine whether it's up to date.

True, but I think it answers a different question, which was "to replace or to overwrite". I do not recall any codepath in git proper (I do not know about third-party tools and scripts around the fringe, though) that overwrites working tree files instead of writing into new files and replacing them.

If there is a hardlink to outside the working tree of a tracked path, and "git reset --hard [<committish>]" needs to modify the contents of that tracked path because it does not match what is recorded in the committish, I think it is the right thing to severe the link and leave the path outside the working tree intact. If we instead overwrote, we will damage "the other file" that shares the hardlink, which is outside the working tree hence outside our control.

Also, if two paths inside a working tree are made into hardlinks to each other, whenever Git needs to update either of them, we would severe the link, i.e. not ovewrite but replace, and it is the right thing to do, since Git trakcs these two paths as two separate things (i.e. the index has one entry for each of these paths).

Previous: brian m. carlsonNext: Michael Herrmann
Message 3 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.