18

I'm fairly new to git via command line, but I've seen that you can use --theirs and --ours to resolve merge conflicts - But this seems to only work with git checkout. Is there a way to do a similar thing when using git stash pop / git stash apply? i.e. When I pop from the stash it creates a load of conflicts. Rather than resolve each one individually, is there a way to instantly resolve them all one way or the other?

Thanks

Kieran
  • 181
  • 1
  • 3

2 Answers2

20

In addition to @r3mus-n0x answer, you should provide the index of stash you want to check out. Then the fatal error should not occur.

$> git stash list
   stash@{0}: WIP on xxx: 466a845fe Fix: Deleted unnecessary comments

$> git checkout stash@{0} --theirs .

Confirmed with git-version 2.28.0

Black
  • 18,150
  • 39
  • 158
  • 271
creep3007
  • 1,794
  • 2
  • 21
  • 22
  • Worked exactly as I was hoping it would. Back of my mind I wonder if a new/untracked file wasn't added... but it was nbd. – Devin Rhode May 04 '23 at 04:29
  • @DevinRhode untracked files are stored differently in stash. They are stored in and you can access them in the third parent. Or you use the commit SHA: # 3rd parent Method $> git checkout stash@{0}^3 -- path/to/file # SHA Method # 1st find the SHA of untracked: $> git log --name-status stash@{0} # then check it out #> git checkout SHA -- path/to/file – creep3007 May 04 '23 at 13:00
  • @DevinRhode here I found a good described post https://stackoverflow.com/a/23609023/2408013 – creep3007 May 04 '23 at 13:52
5

You can still use git checkout with the current directory as an argument:

git checkout --theirs .
r3mus n0x
  • 5,954
  • 1
  • 13
  • 34
  • 6
    That's useful to know, unfortunately this gives an error of: `fatal: '--ours/--theirs' cannot be used with switching branches` – Kieran Jul 20 '18 at 08:12
  • 1
    @Kieran, please provide the exact steps that led you to this error. – r3mus n0x Jul 20 '18 at 12:13