git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Neal Kreitzinger <nkreitzinger@gmail.com>
To: Piotr Krukowiecki <piotr.krukowiecki@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git stash: add --index-only, or --keep-index should not stash index?
Date: Mon, 14 Mar 2011 17:21:54 -0500	[thread overview]
Message-ID: <4D7E9502.4060502@gmail.com> (raw)
In-Reply-To: <4D7A6E37.8080104@gmail.com>

On 3/11/2011 12:47 PM, Piotr Krukowiecki wrote:
> Hi,
>
> I wanted to do something like "Testing partial commits" described in
> git-stash documentation (see end of mail for reference). I think this
> is a common scenario: you start working on some feature, then discover
> a bug, start fixing it, but realize it needs more work. So now you have
> two features that needs more work (both are not ready for committing).
>
> The documentation says to use --keep-index in this case.
>
> The problem is that --keep-index leaves changes in index intact, but at
> the same time it saves them in stash. So if I edit those changes I'm likely
> to get conflicts when applying the stash.
>
> For example:
>
> $ git init&&  echo a>  a&&  git add .&&  git commit -m a
> $ echo x>  a&&  git add a&&  git stash save --keep-index
> $ echo y>  a&&  git add a&&  git commit -m y
> $ git stash pop
> Auto-merging a
> CONFLICT (content): Merge conflict in a
>
> Maybe --keep-index should not stash staged changes? This would fix this
> problem. And I can't  think of a situation when would want to stash changes
> and at the same time keep them.
>
> If --keep-index works correctly maybe a new option, for example --index-only
> (or --cached-only?) could be introduced?
>
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Testing partial commits::
>
> You can use `git stash save --keep-index` when you want to make two or
> more commits out of the changes in the work tree, and you want to test
> each change before committing:
> +
> ----------------------------------------------------------------
> # ... hack hack hack ...
> $ git add --patch foo            # add just first part to the index
> $ git stash save --keep-index    # save all other changes to the stash
> $ edit/build/test first part
> $ git commit -m 'First part'     # commit fully tested change
> $ git stash pop                  # prepare to work on all other changes
> # ... repeat above five steps until one commit remains ...
> $ edit/build/test remaining parts
> $ git commit foo -m 'Remaining parts'
> ----------------------------------------------------------------
>
>
behind-the-scenes, git stash saves your working tree as a commit and 
your index as another commit.  "git-stash apply" and "git-stash pop" 
only apply your stashed-index if you do "git-stash-apply --index".  The 
default is to only apply your stashed-work-tree.  You can create new 
branches from your stashes with "git-stash branch".  You may find that 
much better to deal with for managing your work.  Stashes aren't really 
intended to be the primary way to manage your work, but instead are a 
supplement.  Branches are a better main tool for managing work.  You can 
create a branch from your stash and when the branch is ready you can 
merge it into your other branch.

v/r,
neal

  reply	other threads:[~2011-03-14 22:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-11 18:47 git stash: add --index-only, or --keep-index should not stash index? Piotr Krukowiecki
2011-03-14 22:21 ` Neal Kreitzinger [this message]
2011-03-15 19:48   ` Piotr Krukowiecki
2011-03-16 17:57     ` Neal Kreitzinger
2011-03-16 21:37       ` Piotr Krukowiecki
2011-03-16 22:36         ` Junio C Hamano
2011-03-16 23:06         ` Neal Kreitzinger

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

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

  git send-email \
    --in-reply-to=4D7E9502.4060502@gmail.com \
    --to=nkreitzinger@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=piotr.krukowiecki@gmail.com \
    /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.
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 NNTP newsgroup(s).