Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I have conflicting branches, branch2 branched from branch1.

Let's say when rebasing branch2 on current branch1 while resolving conflicts, I decide to take some (not all) of "their" (i.e. branch1) files as-is. How do I do that?

I tried:

git checkout branch1:foo/bar.java

fatal: reference is not a tree: TS-modules-tmp:foo/bar.java

git checkout refs/heads/branch1:foo/bar.java

fatal: reference is not a tree: refs/heads/TS-modules-tmp:foo/bar.java

1 Answer

0 votes
by (27.5k points)

As pointed out in the  git-rebase docs:

"Note that a rebase merge works by replaying each commit from the working branch on top of the branch. Due to this, when a merge conflict happens, the side reported as ours is the so-far rebased series, starting with <upstream>, and theirs is the working branch. In other words, the sides are swapped."

So in this scenario,

$ git checkout --ours foo/bar.java

$ git add foo/bar.java

In case you rebase a branch feature_x against master (that is running git rebase master while on branch feature_x), during rebasing ours refers to master and theirs to feature_x.

Browse Categories

...