1

I started a rebase of my branch over an updated master. During the rebase there were a few conflicting files which were resolved easily. However, one file is a huge header containing hundreds of macro definitions, which are all conflicting.

I want to simply choose the file version from master, without editing the current conflict-marked file.

How can I do that, without forfeiting the conflict resolution I already did with the other files?

Options are to use command line or TortoiseGit.

ysap
  • 7,723
  • 7
  • 59
  • 122

2 Answers2

3

You might consider having to bring over the changes you have introduced in your branch manually. Let's say your branch is X, then you could do this:

git checkout HEAD -- the-file # have the file exactly as it is in the base branch of the rebase
# now, **manually**, check the differences between "the common ancestor",
# which in a rebase it has a different meaning, and what is being rebased:
git diff HEAD~ REBASE_HEAD -- the-file
# find a way to have the file as it is in your working tree to include those changes that the diff is showing
# when you are done:
git add the-file
git rebase --continue
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Thanks. I did not make any changes to that file. A colleague made in his branch and merged into master. I am now trying to rebase my branch over those changes to master, and that header file shows as conflicting. Looking inside, all the conflicts are mere space characters at end of lines, that were removed in the newer version (currently in master). (And just to emphasize, I am in the middle of the rebase now, don't want to `git rebase --abort`) – ysap Nov 05 '20 at 17:09
  • So, what you want to do is keep the file as it is in master? `git checkout HEAD -- the-file; git add the-file; git rebase --continue`. keep in mind that HEAD _during a rebase_ is the branch that you are rebasing **on**, **not** the branch being rebased. – eftshift0 Nov 05 '20 at 17:40
  • I am on branch X that was branched from master. Made some progress, updated master from remote ("origin") and now trying to rebase my branch X on top of the latest updates made to master. Normally, while in my branch, I'd do `git fetch orign master:master` then `git rebase master` then resolve conflicts and `git rebase --continue`. Then checkout master and merge my branch into master. Now I have this huge file conflict in the middle of the rebase operation. I don't want to `git rebase --abort`. Just to get the master version of the file in question, add it and continue the rebase. – ysap Nov 05 '20 at 17:46
  • Right: `git checkout HEAD -- the-file; git add the-file; git rebase --continue` Use master instead of HEAD if that makes you feel more comfortable... it's the same thing _as long as you do not care for any changes you might have performed on said file on **your branch**_. – eftshift0 Nov 05 '20 at 17:58
  • Thanks, I did not change the file. – ysap Nov 05 '20 at 18:31
1

Considering you're rebasing with master. You can checkout that particular file from master branch, which will override the local copy.

git checkout --theirs my/file.js

(here --theirs tells git to take the file from the branch we're rebasing)

Sam
  • 572
  • 3
  • 11
  • sure about this? In a rebase HEAD is the base branch and REBASE_HEAD is what you are cherry-picking at the moment in the rebase operation. `git checkout` is aware of this distinction when doing a rebase and so it switches their meaning? – eftshift0 Nov 05 '20 at 16:57
  • @eftshift0 Using `REBASE_HEAD` may undo non-conflicting changes that happened in the branch being rebased, i.e. a change that happened a few commits ago but isn't in master. Using `REBASE_HEAD` will add stuff into the current commit that undoes that change. Recommend anyone reading this to use `git show` and `git diff` to avoid making accidental changes like that. – amphetamachine Nov 05 '20 at 17:00
  • This command will change *only* the file in question, right? Then I can `git add my/file.js` and then `git rebase --continue`? – ysap Nov 05 '20 at 17:12
  • Well, after checking out and adding the file, then running `rebase --continue` I got a message that there's nothing changed and maybe I forgot to add my files?? After a little bit more of head banging I decided to abort the rebase. Since the only files that I updated were not conflicting, I wanted to try again and this time checkout *all* of the smaller conflicting files. Ended up giving up on this rebase attempt. I hate git. – ysap Nov 05 '20 at 20:03
  • If you're rebase --continue showing that no files changes, then you could use rebase --skip to skip that particular commit. As you have only one change that is also being replaced with the rebase branch, skip doesn't affect anything else. – Sam Nov 06 '20 at 07:17