0

I had a git history like this:

   master         feature
     v               v  
o----o-----o----o----o

I checked out master, then altered and committed file.txt, which existed in both branches:

git checkout master
...altered file
git add file.txt
git commit -m "altered file.txt"

So then my history looked like this:

       master         
         v                 
o----o---o     feature
      \          v
       o----o----o

Then I rebased feature onto master:

git checkout feature
git rebase master 

I figured that since I had only altered one line in a single file, if there were any merge conflicts they should only be with file.txt. Instead I had several minor conflicts along the way, none related to file.txt.

Example error message:

Falling back to patching base and 3-way merge...
error: The following untracked working tree files would be overwritten by merge:
    path/to/DifferentFile.php
Please move or remove them before you merge.
Aborting
error: Failed to merge in the changes.
Patch failed at ab12 my commit message
hint: Use 'git am --show-current-patch' to see the failed patch

What happened here? Doesn't rebase just play all your commits onto the new tip of the base branch? If the branches were in the same linear history before, how could adding one file and rebasing create merge conflicts with unrelated files?

symlink
  • 11,984
  • 7
  • 29
  • 50
  • If some of your "replay" commits involve renaming files, the old style `git am`-based back end will miss this. Use `git rebase -i` (explicitly interactive) or `git rebase -m` (implied interactive back-end), or use Git 2.26 where `git rebase` now defaults to using the interactive back-end automatically. – torek Apr 30 '20 at 22:23
  • 1
    If that's *not* it, note that the error is talking about an *untracked* file: one that's not in your index right now and presumably not in your current commit. It must be in one of the commits your rebase will copy (and of course in your work-tree right now). You'll need to move the untracked file out of the way to let rebase do its work. – torek Apr 30 '20 at 22:24

0 Answers0