git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Chris Torek <chris.torek@gmail.com>
To: Hongyi Zhao <hongyi.zhao@gmail.com>
Cc: Phillip Susi <phill@thesusis.net>, Git List <git@vger.kernel.org>
Subject: Re: git revert with partial commit.
Date: Tue, 4 Apr 2023 09:19:35 -0700	[thread overview]
Message-ID: <CAPx1Gvcz6f3AQJYfq7Sih0bL6pAi5mHZj8rj=kd7kRDWKLZEzw@mail.gmail.com> (raw)
In-Reply-To: <CAGP6POLx0+OhMJ9oqmK8R9Lq7tppC258NWHNFhqXMbO9smXd+w@mail.gmail.com>

On Tue, Apr 4, 2023 at 9:00 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
[various previous conversations and methods-that-work snipped]
> But I still wonder why the following method doesn't work:
>
> werner@X10DAi:~$ git revert f18fbd1e16a1ca4215621768d17858c036086608
> --no-commit -- Public/CTAN/IDE/phonon/compile-install-phonon
> Public/CTAN/IDE/texstudio-org/texstudio.git.sh
> fatal: bad revision 'Public/CTAN/IDE/phonon/compile-install-phonon'

Neither `git cherry-pick` nor `git revert` allow specifying files.

There are some terminology issues here that, if clarified, may
help you in thinking about all of this.  (Some of these may
involve language translation issues as well.)

In Git, a *commit* is an atomic entity consisting of two parts:
information about the commit itself (metadata such as the name
of the commit's author, some time stamps, and so on) and a
full snapshot of files.

A commit *is not* a *set of changes*.  It *is* a snapshot.  We
can form a sort of "changeset algebra" out of these things,
by which taking two snapshots and subtracting them produces a
delta, in the same way that taking two integers and subtracting
produces a delta:

    delta = v2 - v1

In this algebra:

    v1 + delta = v2

The same works in integer arithmetic, of course.  In integer
arithmetic, a sum of any set of deltas can be used as a new delta.
But this is not true of "source code deltas" since one delta may
show a file being deleted entirely and another delta may show
the same file being changed.  We lose some properties, such as
the ability to do order reversals (commutativity).  So we must
be careful to treat deltas as nothing but deltas, and snapshots
as nothing but snapshots.

Now, `git cherry-pick` means: given some commit, find its parent
(singular), then use that parent/child pair to compute a delta.
Attempt to apply *that* delta to the *current commit and working
tree* snapshot.

Similarly, `git revert` means: given some commit, find its parent
(again, singular), and use that parent/child pair to compute a
delta.  Attempt to reverse-apply that delta to the current commit
and working tree snapshot.

This kind of operation produces a new commit, so there's no such
thing as a partial revert or partial cherry-pick, at least in
terms of "things Git can do by itself".  But we, as humans writing
programs, wish to *achieve* such things.

It's probably wisest to avoid calling these things "partial
reverts" or "partial cherry-picks".  This is the terminology
issue: these phrases make sense to humans, but not to Git.  You, a
human, can achieve these results, but if you ask Git to do a
revert or cherry-pick, Git will attempt to do a revert or cherry-
pick -- not a "partial revert", whatever you mean by that!

To do what you want, you will want to:

 * compute the appropriate delta, then
 * pick and choose some part(s) of this delta to apply or
   reverse-apply

and there are many ways to do that, but none of them involve
using *only* `git revert`.

Chris

  reply	other threads:[~2023-04-04 16:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-02  9:17 git revert with partial commit Hongyi Zhao
2023-04-02 14:16 ` Torsten Bögershausen
2023-04-03 17:07   ` Junio C Hamano
2023-04-04  0:28   ` Hongyi Zhao
2023-04-03 18:29 ` Phillip Susi
2023-04-04  0:20   ` Hongyi Zhao
2023-04-04  0:37     ` Hongyi Zhao
2023-04-04 15:50       ` Hongyi Zhao
2023-04-04 16:19         ` Chris Torek [this message]
2023-04-04 17:21           ` Sergey Organov
2023-04-04 18:20             ` Junio C Hamano
2023-04-04 19:40               ` Sergey Organov
2023-04-04 19:48                 ` Junio C Hamano
2023-04-04 21:14                 ` Felipe Contreras
2023-04-05  6:39                   ` Sergey Organov
2023-04-07  0:24                     ` Felipe Contreras
2023-04-07 17:20                       ` Sergey Organov
2023-04-06 15:48     ` Phillip Susi

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CAPx1Gvcz6f3AQJYfq7Sih0bL6pAi5mHZj8rj=kd7kRDWKLZEzw@mail.gmail.com' \
    --to=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hongyi.zhao@gmail.com \
    --cc=phill@thesusis.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).