Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get "their" changes in the middle of conflicting Git rebase?

I have conflicting branches, feature_x branched from main.

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

I tried:

git checkout main:foo/bar.java
fatal: reference is not a tree: TS-modules-tmp:foo/bar.java
  
git checkout refs/heads/main:foo/bar.java
fatal: reference is not a tree: refs/heads/TS-modules-tmp:foo/bar.java
like image 820
Ondra Žižka Avatar asked Nov 16 '11 03:11

Ondra Žižka


People also ask

How do you continue merge after fixing conflicts?

merge : add ' --continue ' option as a synonym for ' git commit ' Teach ' git merge ' the --continue option which allows 'continuing' a merge by completing it. The traditional way of completing a merge after resolving conflicts is to use ' git commit '.

How do I save rebase changes in Git?

To save your changes and exit the document, type :wq! and press Enter key. It should appear at the end of the document like this. To exit the document without saving, type :q! and press Enter key.


2 Answers

You want to use:

git checkout --ours foo/bar.java
git add foo/bar.java

If you rebase a branch feature_x against main (i.e. running git rebase main while on branch feature_x), during rebasing ours refers to main and theirs to feature_x.

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. Because of 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.

For further details read this thread.

like image 100
iGEL Avatar answered Oct 12 '22 01:10

iGEL


If you want to pull a particular file from another branch just do

git checkout branch1 -- filenamefoo.txt

This will pull a version of the file from one branch into the current tree

like image 42
Adrian Cornish Avatar answered Oct 12 '22 00:10

Adrian Cornish