0

I want to be able to apply a stash that looks like this:

git stash show --stat stash@\{1\} 
 extensions/99/fill-thresholds.json            |  2 +-
 html/js/1.js                           | 10 ++++++++++
 html/pages/su/2.html            |  4 ++--
 html/pages/su/popups/3.html | 21 +++++++++++----------
 sql/2 - data/4.sql              |  6 +++---
 sql/3 - keys/5.sql               |  4 ++--
 sql/5 - views/6.sql          |  2 +-
 7 files changed, 30 insertions(+), 19 deletions(-)

When I try to apply that stash I get a conflict error:

git stash apply stash@\{1\} 
Auto-merging sql/2 - data/4.sql
CONFLICT (content): Merge conflict in sql/2 - data/4.sql

And then I have tried to resolved the conflict but then my other files were not applied, if I run the apply that stash again I get that conflict error again.

I don't really care about the file with the error so I was thinking if there's a way to discard that file only from the stash so when I try to apply it I don't get that error or how can I continue applying the stash after I resolved the conflict?

2
  • Could you elaborate on "my other files were not applied"? That's impossible: the stash is not applied on a file-by-file basis; instead, all changes are applied at once, just application of some of them may result in conflicts. So I'd inspect what git status tells you after git stash apply more closely. May be you just forgot to commit?
    – kostix
    Commented Sep 25, 2015 at 18:12
  • By the way, discarding a conflict in such a case is simple: use git checkout --ours "sql/2 - data/4.sql" and then git add it to the index. --ours means our local version (the one at the HEAD), and --theirs` means the version in the stash.
    – kostix
    Commented Sep 25, 2015 at 18:14

2 Answers 2

3

I'm not sure if there is a way to modify a stash, but I would just pop the stash in a new branch that doesn't have any conflicts, remove the files that you don't care about, and then stash/reapply on your branch of interest.

4
  • Thank you @Jin, or is there any other command to run after I resolved the conflict so I can continue with the stash apply? Commented Sep 24, 2015 at 19:14
  • BTW, you can create a branch from a stash via stackoverflow.com/questions/6925099/…. See answer by Rodney Golpe. Commented Sep 24, 2015 at 19:15
  • Ok I have the files in the other branch, how can I pass those files to the original branch without stashing again in this temporary branch and transfering them again? Commented Sep 24, 2015 at 19:32
  • Hmm, yeah my idea was to just git stash, git checkout other_branch, git stash pop.
    – Jin
    Commented Sep 24, 2015 at 20:27
1

It looks like you can merge directly from a stash "git merge stash@{XX}' and use the rerere mechanism to handle your repeated merge conflicts, see https://git-scm.com/blog/2010/03/08/rerere.html

Not the answer you're looking for? Browse other questions tagged or ask your own question.