简体   繁体   中英

Apply stash patching and without stage

I'm looking for a way for apply my stash patching it in order to see what I'm applying step by step.

If I do git stash apply 0

  • automatically merges all and if, after I run git diff I can't see the changes. it's like it automatically stage all.

  • only if, after have applied, in one file there are some conflicts, I can solve the conflicts and, after have done that, I can see the changes not staged.

How can I have more control during the apply process and not having the code all applied and already staged?

Thanks!

How can I have more control during the apply process and not having the code all applied and already staged?

You can't—at least, to a first approximation anyway.

The problem is that git stash apply uses the merge engine to do the applying. The merge engine uses both Git's index and your working tree. The term index here refers to the same data structure, stored in the same location, as the term staging area . So git stash apply will use—and thus mess with—the staging area.

As phd commented , though, you don't have to use git stash apply . Using git stash show -p gets you a patch, which you can then feed through various patch-handling operations.

There's one other way to attack this: Git doesn't always have to use the (main) index. You can establish a second, temporary index and have git stash apply operate in this second index. If you do try this, be careful. You'll probably need to populate your temporary index, using either git read-tree or just copying the main index to your temporary index.

None of these are methods I'd recommend, though when you get to this point, I recommend avoiding git stash as much as possible in the first place. The reason is simple enough: you've already encountered it. The stash code works by making commits. These commits have, internally, the form of a merge, which means that the rest of Git can't use these commits very well. Only git stash itself knows how to use these special stash commits. If, instead of making these special stash commits, you just make ordinary commits... well, the rest of Git knows perfectly well how to work with ordinary commits. You now have the entire Git suite available. You don't have to reach deep into Git to trick it; you don't have to sidestep things to turn a stash into a patch. All the tools just work, in the ordinary way, on these ordinary commits.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM