Re: BUG? git stash and immediate git apply results in conflict

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> wrote:
>
> On Wed, Jun 1, 2022 at 2:11 PM Akos Vandra-Meyer <axos88@xxxxxxxxx> 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux