Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Stash equivalent of --theirs

Tags:

git

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

like image 411
Kieran Avatar asked Jul 19 '18 16:07

Kieran


People also ask

What is equivalent of git stash?

Shelving is the closest equivalent of git stash, as explained in Douglas Leeder's answer.

What is theirs in git?

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).

How do you stash conflicts?

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.

What does git checkout theirs do?

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 .


1 Answers

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

like image 149
creep3007 Avatar answered Nov 13 '22 00:11

creep3007