git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: Michael Herrmann <michael@herrmann.io>, git@vger.kernel.org
Subject: Re: A puzzle: reset --hard and hard links
Date: Wed, 19 Jan 2022 14:37:20 -0800	[thread overview]
Message-ID: <xmqqilufl5cv.fsf@gitster.g> (raw)
In-Reply-To: <YeiOoAcM7TMK2pgz@camp.crustytoothpaste.net> (brian m. carlson's message of "Wed, 19 Jan 2022 22:20:16 +0000")

"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).

  reply	other threads:[~2022-01-19 22:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19 20:37 A puzzle: reset --hard and hard links Michael Herrmann
2022-01-19 22:20 ` brian m. carlson
2022-01-19 22:37   ` Junio C Hamano [this message]
2022-01-20  8:59     ` Michael Herrmann
2022-01-20 22:20       ` brian m. carlson
2022-01-21 12:50         ` Michael Herrmann
2022-01-24 13:48           ` Michael Herrmann
2022-01-24 18:07             ` Junio C Hamano
2022-01-24 18:16               ` Michael Herrmann
2022-01-24 21:19                 ` Junio C Hamano
2022-01-24 21:50                   ` Michael Herrmann
2022-01-25  8:49                     ` Andreas Schwab
2022-01-25 11:33                     ` Ævar Arnfjörð Bjarmason
2022-01-25 13:29                       ` Andreas Schwab
2022-01-25 14:30                         ` Michael Herrmann
2022-01-26  2:14                           ` brian m. carlson
2022-01-26 18:46                             ` Junio C Hamano
2022-01-24 22:18                   ` rsbecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqilufl5cv.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=michael@herrmann.io \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).