git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Elijah Newren <newren@gmail.com>
Cc: Jeff King <peff@peff.net>,
	Fedor Biryukov <fedor.birjukov@gmail.com>,
	Bagas Sanjaya <bagasdotme@gmail.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: Aborting 'rebase main feat' removes unversioned files
Date: Sun, 05 Sep 2021 15:31:50 -0700	[thread overview]
Message-ID: <xmqqr1e2ejs9.fsf@gitster.g> (raw)
In-Reply-To: <CABPp-BFyR19ch71W10oJDFuRX1OHzQ3si971pMn6dPtHKxJDXQ@mail.gmail.com> (Elijah Newren's message of "Sat, 4 Sep 2021 22:32:57 -0700")

Elijah Newren <newren@gmail.com> writes:

> unpack_trees.  In fact, it traces back to (and before)
>     fcc387db9b ("read-tree -m -u: do not overwrite or remove untracked
> working tree files.", 2006-05-17)
> which has additional commentary over at
> https://lore.kernel.org/git/7v8xp1jc9h.fsf_-_@assigned-by-dhcp.cox.net/.
> It appears that before this time, git happily nuked untracked files
> and considered them expendable, in basically all cases.  However, this
> patch continued considering them as expendable whenever opts->reset
> was true.

Thanks for digging.  Yes, the 'reset' bit was treated as the license
to kill untracked working tree files and directories that get in the
way in order to carry out the unpack_trees operation.

> So, then...should we preserve untracked (and non-ignored) files in all
> these cases?  This rebase case seems clear, but others might be less
> clear....

In short, the guiding principle ought to be that "checkout --force"
and anything that is given "force" as a stronger override should be
allowed to do whatever minimally necessary to match the end result
in the working tree to what the command wants to show in the absense
of these untracked paths.  And without being forced, untracked and
unignored paths are precious and should cause commands to fail, if
they need to be touched for the commands to complete what they are
asked to do [*].

"reset --hard HEAD" is an oddball.

Naïvely, because it is often used as the way to tell Git to "no
matter what, match the working tree to HEAD", even though it does
not have an explicit "--force" on the command line, it feels that it
also should be allowed to do whatever necessary to the working tree
files.  And historically, that is what we wanted to implement.  If
we suddenly made it "safer", I am sure a lot of existing things will
break.

But unfortunately, "--hard" means a bit more than that in the
context of "reset", in that we want to reset in a way that is
different from "--mixed" (reset the index only without touching the
working tree) and "--soft" (do not touch the index or the working
tree), more specifically, with "--hard", we want to reset both the
index and the working tree to match the given committish (often
"HEAD").  From that point of view, "reset --hard" that tries to
preserve untracked and unignored paths, and "reset --force --hard"
that does whatever necessary to untracked and unignored paths to
match the working tree files, when they reset the index and the
working tree to the named committish, may have made sense.  If we
were designing the feature without any existing users, it is no
brainer to imagine that our design would: (1) call the three 'reset'
modes as "both", "index-only" and "neither", instead of "hard",
"mixed" and "soft", and (2) require "--force" to touch untracked and
unignored paths.

And I think that may be a reasonable longer-term goal, but since we
have existing users and scripts, we cannot go there overnight without
devising a migration path.

Thanks.


[Footnote]

* We sometimes talk about adding a precious category of paths that
  are "ignored", but this discussion is orthogonal to that.  Things
  that are not tracked and not ignored ought to be precious in
  principle.

  parent reply	other threads:[~2021-09-05 22:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAG2t84Uaw-Kdp+EXU8CY1QYfykFQj-hGLJnTSH8MYO8Vi_yqgA@mail.gmail.com>
2021-09-03 20:33 ` Aborting 'rebase main feat' removes unversioned files Fedor Biryukov
2021-09-04  6:57   ` Bagas Sanjaya
2021-09-04  9:48     ` Jeff King
2021-09-04  9:51       ` Fedor Biryukov
2021-09-04  9:58         ` Fedor Biryukov
2021-09-04 10:03           ` Fedor Biryukov
2021-09-04 10:24             ` Jeff King
2021-09-04 18:32               ` Fedor Biryukov
2021-09-04 10:18         ` Jeff King
2021-09-05  5:32           ` Elijah Newren
2021-09-05  7:43             ` Ævar Arnfjörð Bjarmason
2021-09-05 10:05               ` Fedor Biryukov
2021-09-08  0:40               ` Elijah Newren
2021-09-05 22:31             ` Junio C Hamano [this message]
2021-09-08  0:41               ` Elijah Newren

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=xmqqr1e2ejs9.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=bagasdotme@gmail.com \
    --cc=fedor.birjukov@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    --cc=peff@peff.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).