Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - confusion over terminology, "theirs" vs "mine"

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?

like image 417
CaptSaltyJack Avatar asked Aug 04 '15 19:08

CaptSaltyJack


People also ask

What is mine and theirs git?

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

What happens in git when a conflict occurs between your changes and someone else's?

Two ways git merge/git pull can fail This occurs because you have committed changes that are in conflict with someone else's committed changes. Git will do its best to merge the files and will leave things for you to resolve manually in the files it lists.

How does git know there is a conflict?

Git has an internal merge system that is independent of difftool . So Git decides when a change causes a conflict on its own, not by using whatever external diff or merge tools you're using (which probably use their own conflict detection and resolution strategies).

What is mine and theirs in SourceTree?

'Mine' refers to the changes that you just made . 'Theirs' would refer to the changes made by the other team member.


2 Answers

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.

like image 191
Keith Avatar answered Sep 28 '22 20:09

Keith


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

like image 39
mipadi Avatar answered Sep 28 '22 21:09

mipadi