0

I'm looking for the "moral equivalents" of

% git stash pop --theirs

and

% git stash apply --theirs

...where the hypothetical1 --theirs flag stands for: "whenever a merge is required, always accept the stashed version".

What's the simplest way to achieve the same effect?

Also, for the sake of completeness (although I've never needed it), I'd be interested in knowing how to achieve the equivalent of

% git stash pop --ours

% git stash apply --ours

1 Curiously, git has no objection to the --theirs flag shown above, though it is not documented in the man page for git-stash, so I don't know what it's supposed to do, if anything. Whatever this is, it does not resemble the description of my "hypothetical" --theirs flag above.

kjo
  • 33,683
  • 52
  • 148
  • 265
  • Ours and theirs are a thing in Git. They're used to name the branches when merging as far as I know. I can't wrap my head around it however and I don't think it is really worth the trouble. You can read this post to get started: [What is the precise meaning of “ours” and “theirs” in git](http://stackoverflow.com/a/25576672/5185571). Note that the flags `--ours` and `--theirs` exist at least for checkout. Finally, if git detect conflicts, you surely need to do the merge manually so that you don't completely break your code. – A wild elephant Oct 01 '15 at 15:00
  • @Awildelephant: thanks, but I am fully aware of the significance of `--theirs` and `--ours` in the context of `git` commands; this is precisely why I chose those particular flags for this question. The fact remains that those flags are not mentioned in the documentation for `git-stash`, and in my experience, `git` is not very forgiving when it gets flags in a context it does not expect. – kjo Oct 01 '15 at 15:53
  • I have no idea what `git` has to do with morality... I would posit that `git` is pretty much a-moral (not the same thing as immoral). – twalberg Oct 01 '15 at 16:18
  • @twalberg: you might generally (and validly, I think) object to this as abuse of language :-) but I'll note that the phrase "moral equivalent" is nopw not uncommonly used in a context where morality is irrelevant, e.g., https://ultimaker.com/en/community/view/10516-service-manual-or-moral-equivalent-thereof-for-um2-in-particular-how-to-reattach-the-filament-driver – torek Oct 01 '15 at 22:31

1 Answers1

1

The git stash script was not good about complaining about unknown flags. This was improved in commit d6cc2df5c80dc4f52a56679baa5e32539eb028b1 (tags suggest this was first officially part of git as of v2.4.4). If you don't have that version, the --ours and --theirs arguments are just quietly ignored.

In the case of apply and pop, the script calls git merge-recursive directly, but never passes on flags. You could copy the script and edit it to add the ability to pass on -X and arguments. (To see the script git is running for you, look at $(git --exec-path)/git-stash.) It may be a bit trickier than that, though, since applying a stash means applying both the index version (the revision specified by the stash ID) and the work-tree version (that commit's second parent).

torek
  • 448,244
  • 59
  • 642
  • 775