git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Tim Chase <git@tim.thechases.com>
To: git@vger.kernel.org
Subject: Stashing just index..working-copy rather than HEAD..working-copy?
Date: Wed, 24 Apr 2024 08:44:09 -0500	[thread overview]
Message-ID: <ZikMqXeDnOqK_wlq@thechases.com> (raw)

A while back[1] I'd encountered a situation and sparred my way
around it, but was hoping there was a better solution.

I'd done a

  $ git add -p

to selectively add things that I wanted in the next commit.
So I wanted to stash the changes that appeared in

  $ git diff

and test just the changes I was about to commit so I did a

  $ git stash

However, that reset my index and stashed everything HEAD..working-copy.
Okay, my fault.  There's a --keep-index that isn't default, so I
carefully re-staged my commit with another

  $ git add -p

and did

  $ git stash --keep-index

to keep the index.  Great.  My index was still good.  But when I went to

  $ git stash pop

as described in `git help stash` under the "Testing partial commits"
it generated conflicts because it had still stashed HEAD..working-copy
(as confirmed with a `git stash show -p`) rather than index..working-copy
and some of those popped changes were already in the working-copy/index.

To work around it, I re-staged my index yet again:

  $ git add -p

and then did

  $ git diff > temp.diff
  $ git reset --staged

did my testing, and then re-applied the temp.diff patch to the
working-copy to get back to where I'd been.  Conflict-free as
expected.

As a slight improvement, /u/splettnet suggested actually committing
a dummy-commit:

  $ git add -p
  $ git commit --allow-empty-message
  $ git stash

at which point I could build/run/test and then resetting to uncommit:

  $ git stash pop
  $ git reset --soft HEAD~1

which I've been using since.  However, I was wondering if there was
a better way to instruct git-stash to stash index..working-copy
instead of HEAD..working-copy (and leave the index alone in the
process) in the first place.

Thanks,

-tkc

[1]
https://www.reddit.com/r/git/comments/vchu83/stashing_only_unstaged_changes/







             reply	other threads:[~2024-04-24 13:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-24 13:44 Tim Chase [this message]
2024-04-24 22:17 ` Stashing just index..working-copy rather than HEAD..working-copy? Chris Torek
2024-04-24 23:31   ` Junio C Hamano
2024-04-27 20:17   ` Tim Chase

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=ZikMqXeDnOqK_wlq@thechases.com \
    --to=git@tim.thechases.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).