git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: Phillip Susi <phill@thesusis.net>
Cc: Git List <git@vger.kernel.org>
Subject: Re: git revert with partial commit.
Date: Tue, 4 Apr 2023 08:37:08 +0800	[thread overview]
Message-ID: <CAGP6POJr63o67k+7BeokM-pkPbXYrQy4kcWwMXTfoeuFaPaADQ@mail.gmail.com> (raw)
In-Reply-To: <CAGP6POLVpjxO91s1dX98TLepXMrybSWq9y8qJ6b7w+e0SRJT1A@mail.gmail.com>

On Tue, Apr 4, 2023 at 8:20 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Tue, Apr 4, 2023 at 2:36 AM Phillip Susi <phill@thesusis.net> wrote:
> >
> >
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > > Hi here,
> > >
> > > I want to revert a previous commit partially, as follows:
> > >
> > > werner@X10DAi:~$ git log |grep -A3 -B5 -m1 texstudio
> > > commit f18fbd1e16a1ca4215621768d17858c036086608
> > > Author: Hongyi Zhao <hongyi.zhao@gmail.com>
> > > Date:   Sun Aug 1 20:01:02 2021 +0800
> > >
> > >     deleted:    Public/CTAN/IDE/phonon/compile-install-phonon
> > >     deleted:    Public/CTAN/IDE/texstudio-org/texstudio.git.sh
> > >     modified:   Public/repo/github.com/Dushistov/sdcv.git.sh
> > >     deleted:    Public/repo/github.com/goldendict/stardict-relative/bigdict
> > >
> > > More specifically, I just want to revert the following ones:
> > >
> > >     deleted:    Public/CTAN/IDE/phonon/compile-install-phonon
> > >     deleted:    Public/CTAN/IDE/texstudio-org/texstudio.git.sh
> > >
> > > Is this possible?
> >
> > If you are comfortable with git-gui and gitk, then I would say just
> > revert it, then click ammend the previous commit in git-gui, and click
> > to unstage the changes you DON'T want to revert, then commit.  If you
> > want to do it from the command line, then git-revert, then git checkout
> > HEAD~1 -- ( the other 4 file names here ) will get back the other 4
> > files then you can git commit --amend.  Alternatively you can skip
> > git-revert and instead git checkout f18fbd1e16~1 -- (the two files that
> > you DO want to revert), then git commit.
>
> Thanks for your tips. I've also figured out the similar solution based
> on the comment here [1], as shown below:
>
> $ git show f18fbd1e16a1ca4215621768d17858c036086608 --
> Public/CTAN/IDE/phonon/compile-install-phonon
> Public/CTAN/IDE/texstudio-org/texstudio.git.sh | git apply --reverse
> --3way
>
> Because the commit I want to revert is done a long time ago, which is
> not the parent of the commit I'm currently on, so I can't use the `~1`
> which indicates that I want to go back one commit from my current
> position.

Sorry for my inappropriate description above. In fact, it's a more
concise method which also will do the trick, aka, as follows:

$ git checkout f18fbd1e16~1 --
Public/CTAN/IDE/phonon/compile-install-phonon
Public/CTAN/IDE/texstudio-org/texstudio.git.sh

> [1] https://stackoverflow.com/questions/5669358/can-i-do-a-partial-revert-in-git
>
> Best,
> Zhao

  reply	other threads:[~2023-04-04  0:37 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 [this message]
2023-04-04 15:50       ` Hongyi Zhao
2023-04-04 16:19         ` Chris Torek
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=CAGP6POJr63o67k+7BeokM-pkPbXYrQy4kcWwMXTfoeuFaPaADQ@mail.gmail.com \
    --to=hongyi.zhao@gmail.com \
    --cc=git@vger.kernel.org \
    --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).