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
Shelving is the closest equivalent of git stash, as explained in Douglas Leeder's answer.
The 'ours' in Git is referring to the original working branch which has authoritative/canonical part of git history. The 'theirs' refers to the version that holds the work in order to be rebased (changes to be replayed onto the current branch).
Here is an example of a git stash merge conflict and the steps used to resolve it. First, initialize a Git repository, create a file and add it to the index. A commit with the message "First commit" occurs. The file will then be edited by a developer, stashed, edited again and then made part of a commit.
Use --theirs to keep the version from the branch being merged in. And --theirs accomplishes the opposite. If we want to discard the version of myscript.py that resides in our current branch and keep the version from master , we can use --theirs .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With