git - confusion over terminology, "theirs" vs "mine"
Asked Answered
S

3

39

I'm completely confused about what mine vs theirs means. In this specific case, I've got a feature branch where I just squashed about 80 commits via rebase -i and am merging this back into develop. I got a few conflicts, and I just want to use whatever code is on my feature branch. I tried "mine" but that actually seemed to do the opposite.

Could someone shed some light on this terminology?

Shot answered 4/8, 2015 at 19:3 Comment(0)
C
70

ours and theirs is a somewhat confusing concept; exacerbated when performing a rebase:

When performing a merge, ours refers to the branch you're merging into, and theirs refers to the branch you are merging from. So if you are trying to resolve conflicts in the middle of a merge:

  • use ours to accept changes from the branch we are currently on
  • use theirs to accept changes from the branch we are merging into.

That makes sense, right?

When rebasing, ours and theirs are inverted. Rebases pick files into a "detached" HEAD branch. The target is that HEAD branch, and merge-from is the original branch before rebase. That makes:

  • --ours the anonymous one the rebase is constructing, and
  • --theirs the one being rebased;

I.e., rebasing replays the current branch's commits (one at a time) on top of the branch that we intend to rebase with.

Chrysarobin answered 4/8, 2015 at 19:44 Comment(6)
You say "theirs refers to the branch you are merging from" and then "use theirs to accept changes from the branch we are merging into" - huh?Ohm
Poor use of the term "into". If I'm on a branch, and want to merge with master, running "Git checkout --theirs filename(s)" will give master's files precedence, this overwriting my branch's copies. "--ours" is the opposite, giving my branch precedence in the mergeChrysarobin
Hmm, I find the question which perfectly matches my confusion. I read the well-voted answer several times, and still don't know the answer to any level of confidence. Back to Google.Swacked
@Swacked I can try to rephrase if you can articulate specifics of what’s unclearChrysarobin
Confusion comes from 'the branch we are currently on' and 'the branch we are merging into' being the same thing. I think what you mean for the second one is 'the branch we are merging into the branch we are on'. I think a clearer way of saying the second case is 'to accept the changes from the branch you are merging'Ventricose
All contradictory answers. When you are in Gitlab making a merge from a branch comparison, you are not actually "into" any branch in particular, at least you don't explicitly know. "Source" and "target" branch would be more explicit terms when you are not using the command line.Watters
W
24

"Ours" (and "mine") refer to the current branch; "theirs" refers to the branch being merged in. It sounds like you actually wanted to use "theirs".

Winebaum answered 4/8, 2015 at 19:13 Comment(2)
sometimes, straight forward answer is great. UP voteClovis
i think it is the opposite.Phelips
I
-1

I admit it is confusing at first 🙈. I even wrote an article about this to explain in detail how this works.

In short: "mine" is the change you're holding in your branch, "theirs" is the target branch that everything is going into.

Illyrian answered 30/3, 2021 at 10:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.