2

There are plenty of SO answers and tutorials on the web that say there is a difference between which branch is ours and which branch is theirs depending on whether it's a rebase or a merge, and explain why, usually with a handy table, as do the man pages and online docs (sans the table).

Thing is, I don't care to remember. I'm not a fan of cognitive load for trivial things that the computer should be able to tell me or simply show me.

Is there a command or ENV var or suchlike that contains this information? (A search of my env brings up nothing but maybe I need to enable something first). The kind of thing I can stick in the prompt would be perfect. If it can handle the middle of rebase with a conflict where the target branch becomes a reference to the commit reached, that would be even better.

halfer
  • 19,824
  • 17
  • 99
  • 186
ian
  • 12,003
  • 9
  • 51
  • 107
  • Technically speaking, everything is yours. The problem is intractable because in a conflict that occurs mid-rebase, you're copying commits on top of copied commits, so even if you want to say that some original commit was "yours" and some other original commit was "theirs", by now "yours" and "theirs" have been co-mingled. However, `--ours` is mostly reliably the same as `HEAD` (except for conflicts that occur due to `git stash apply`). – torek Jan 09 '20 at 06:51
  • @torek That's interesting, thanks. – ian Jan 09 '20 at 09:16

2 Answers2

2

As I explained here:

whatever HEAD's pointing to is "ours"

The one tool that makes crystal clear what is ours vs theirs is VSCode. See "Resolve merge conflicts"

  • The current change are ours.
  • The incoming change are theirs.

https://raw.githubusercontent.com/microsoft/vscode-tips-and-tricks/master/media/resolve_merge_conflicts.gif

halfer
  • 19,824
  • 17
  • 99
  • 186
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

When you merge A to B, where A and B are commit-ish(more than branches), B is ours and A is theirs. As commits, B = HEAD and A = MERGE_HEAD.

When you rebase A onto B, B is ours and A is theirs. As commits, B = HEAD and A = REBASE_HEAD.

When you cherry-pick A to B, B is ours and A is theirs. As commits, B = HEAD and A = CHERRY_PICK_HEAD.

You can use commands against HEAD, MERGE_HEAD, REBASE_HEAD and CHERRY_PICK_HEAD, like git show MERGE_HEAD.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53