Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "ours" and "their" while doing git rebase

I have applied the following commands, but have little confusion in doing rebase - what is ours and theirs in the following commands

git checkout app/dashboard-sprint-5
git rebase app/demandware

I know the current branch is app/dashboard-sprint-5 and when i apply the rebase.

app/dashboard-sprint-5 will be applied on the top of app/demandware.

What is ours and theirs in terms of branches.

I have checked the link but not satisfied

like image 990
Shan Khan Avatar asked Dec 13 '17 12:12

Shan Khan


Video Answer


2 Answers

Briefly, when we are talking about rebase, ours means the base branch.

So in your case ours will be app/demandware, since firstly git moves us there, and then applies changes from the app/dashboard-sprint-5, which will be theirs.

For example, here the note from documentation about rebase and ours word:

Because git rebase replays each commit from the working branch on top of the <upstream> branch using the given strategy, using the ours strategy simply discards all patches from the <branch>, which makes little sense.

like image 171
mmelnik Avatar answered Nov 16 '22 00:11

mmelnik


In order to easily remember the direction of ours and theirs, think of rebasing as cherry-picking each commit of the current branch onto the target branch.

Before rebasing:
    A--B--C (master)
       '--D--E (devel, HEAD)

Reset HEAD to master:
    A--B--C (master, HEAD)
       '--D--E (devel)

Cherry-pick D, E.
    A--B--C (master)
       |  '-- D'--E' (HEAD)
       '--D--E (devel)
HEAD becomes "ours" and the old devel branch "theirs".
              ^^^^                            ^^^^^^

On success, repoint devel to E':
    A--B--C (master)
          '--D'--E' (devel, HEAD)

In a non-interactive rebase that goes through without conflicts, it looks like we jump straight from the old devel-branch history to the rebased devel-branch history. In this view the inversion of ours and theirs isn't apparent, leading to potential confusion, especially also during merge conflict resolution – it is simply a bit unexpected, that the branch we started from may suddenly be called "remote branch" by merge tools.


Though this question was already answered, I add this more visual explanation, since I found it difficult to remember the result without.

like image 40
kdb Avatar answered Nov 16 '22 02:11

kdb