git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Akos Vandra-Meyer <axos88@gmail.com>
To: Chris Torek <chris.torek@gmail.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: BUG? git stash and immediate git apply results in conflict
Date: Thu, 2 Jun 2022 13:31:33 +0200	[thread overview]
Message-ID: <CAHHcNodnB8gnaLgxW-vr6PxHh_YjCOAf7CTuot-CJsonb1mdnA@mail.gmail.com> (raw)
In-Reply-To: <CAPx1GvfQLP3q-SvW38=VOxoAmQpMMau_UfXXXQiZSV3NOJCs0w@mail.gmail.com>

Hi Chris,

Thanks for getting back to me on this.
My use case is the following:

I made a bunch of (loosely related) changes to my code, but I have
been asked to submit them as separate commits, so I need to separate
the changes to dependent files relating to the first and second
feature.

So I need to separate the changes in my workdir into two commits
(let's call them two features). Turns out the first feature needs a
dependent file changed in one way, and the second feature improves on
it, so it needs it changed in another way - normally this would result
in a conflict if they would have been done separately in different
branches.

I start off by stashing everything except stuff directly relating to
the first feature and stashing everything else. Check for build
errors, unstage, and incrementally staging more stuff that need to be
added in order to make the first feature build correctly. At some
point I reach the file that has to be changed differently, so I will
have a set of changes staged for that file, while another set of
changes remain unstaged - the changes that will be required by the
second feature.

At this point you pointed out that apparantly I'm misusing git, but I
am confused on how to correctly stash the unstaged changes to check if
the code would build with the staged changes only, and unstage them
and add more stuff if not?

Thanks,
  Akos





On Thu, 2 Jun 2022 at 08:32, Chris Torek <chris.torek@gmail.com> wrote:
>
> On Wed, Jun 1, 2022 at 2:11 PM Akos Vandra-Meyer <axos88@gmail.com> wrote:
> >  git stash -ku
> >  git stash pop
>
> This is not a bug in `git stash` itself, but rather in the way you're using it.
>
> There are two mistakes on your part here:
>
> 1: You are using `-k`, aka `--keep-index`. This flag is intended for usages
> that are not yours here.
>
> 2. You are *not* using `--index` in your `git pop`.  The `--index` flag is
> intended for the kind of thing you are doing here.
>
> It's a bit unfortunate (and perhaps worth some work in the documentation)
> that the `--keep-index` and `--index` flags sound so similar, and yet are so
> different.  The documentation could use some examples here, I think.
>
> Note that if you *do* want to use `--keep-index` during the `git stash` step,
> you will need a `git reset --hard` before your `git stash apply --index &&
> git stash drop` step (aka `git stash pop --index`).
>
> Chris

  reply	other threads:[~2022-06-02 11:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01  6:55 BUG? git stash and immediate git apply results in conflict Akos Vandra-Meyer
2022-06-02  6:32 ` Chris Torek
2022-06-02 11:31   ` Akos Vandra-Meyer [this message]
2022-06-02 12:24     ` Chris Torek

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=CAHHcNodnB8gnaLgxW-vr6PxHh_YjCOAf7CTuot-CJsonb1mdnA@mail.gmail.com \
    --to=axos88@gmail.com \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    /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).