On Wednesday, May 15, 2013 12:11:12 PM UTC+2, Jakob van Bethlehem wrote:

> Hello all,
>
> My first message here. After switching from svn/hg to git and getting some 
> experience, I feel I'm ready to figure out which questions aren't too 
> obvious. My feeling is the current question isn't.
>
> Today I was hacking away, only to discover that I was really working on 
> too much stuff at once. I wanted to stash away a sub-set of my changes, and 
> leave the rest to focus on first. So I did a 'git stash --patch', selected 
> the patches I wanted to move away for now. Only to discover that I stashed 
> away 2 patches too many .... Bummer.


> Alas: I kind of hoped I could do something like 'git stash apply --patch 
> stash@{1}'...... but that didn't quite work: I just got the full stash 
> applied on top of the working directory (to be verbose: this was done after 
> stashing the remaining patches).
> I hope my situation was explained clearly enough. My question is not about 
> how to recover. That's easy by redoing the original stash command, but 
> properly this time. My question is more about learning something more about 
> git, in case I end up in the same, or a similar situation in the future:
> * is there a way to force 'git stash --patch' to create a separate stash 
> for each patch that I select? This would make it possible to apply each 
> patch again afterwards, and would have been a perfect solution in my case 
> as well
>

This sounds a bit weird. I doubt it is possible to do this kind of workflow 
using git stash.

The normal Git way is to keep draft work in the work-tree, and then 
gradually add it to the index and commit as you grow more certain of what 
you want to include. It sounds like what you want to do is to use the stash 
as your work-in-progress area.

Think of the stash more as a temporary commit you store in a branch, while 
you go back to a clean working tree to work on something else (cause that's 
kind of what it is anyway).

One workflow you could try out is with the --keep-index option. This is 
explained in the git stash man 
page<https://www.kernel.org/pub/software/scm/git/docs/git-stash.html>
:

       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'
 
I would recommend you to try out this approach and see if it works. I know 
it feels a bit awkward to pop a stash that includes changes that you have 
already committed, but it works fine (Git understands that these are the 
same contents and will not create conflicts).

* otherwise, is there a way to achieve the result I had hoped for when 
> running 'git stash apply --patch', namely to selectively apply hunks
>

The do-it-yourself-solution is to work with patches the old-fashioned way. 
Save git diff output to patch files, and get them out again using git apply.

In case the answer to both of these is 'No', what would be the proper way 
> and/or place to suggest such a feature?
>

The place to go to suggest features is the git developer 
list: https://gist.github.com/tfnico/4441562

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to