0

I have two different branches. The newer branch has had its directory structure completely changed.

It's something like:

Old branch:
project/
    manager/
        widgets/
        components/
        workers/

New branch:
factory/
    widgets/
    components/
    workers/

Git recognized some but not all of the directory changes, so when I merge changes made in the older branch to the newer branch, it recognizes that they should be made in the corresponding directory in the newer branch.

So for example if I make a bug fix in the old branch on project/manager/widgets/utils.py it also gets updated on factory/widgets/utils.py.

However, for some reason some of the corresponding directories didn't get associated. So when I do a merge there are many files that are marked as deleted in the newer branch. So for example if I make an improvement in the old branch to project/manager/workers/base.py the merge reports:

CONFLICT (modify/delete): project/manager/workers/base.py deleted in HEAD and modified in old-branch. Version old-branch of project/manager/workers/base.py left in tree.

I'm wondering if there's some way I can indicate to git that folder project/manager/workers/ is the same as factory/workers.

Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161
  • Git does not record "folders" (directories) in that manner. Instead, Git has its own special dynamic detection, computing *file identity* (ie whether `a/b/c/base.py` should be matched with `d/e/f/base.py`) at `git diff` time. Git could use some kind of assistance sometimes, but it's not (currently?) available. See my answer here: http://stackoverflow.com/a/40352403/1256452 – torek Dec 11 '16 at 22:29
  • Okay so I guess at this point there's nothing really to be done? – Jordan Reiter Dec 11 '16 at 22:31
  • You can fuss with the `-M` setting (a lower value makes Git happier to match files; when it's set extremely low, Git will match entirely-unrelated files, which is probably even worse :-) ) and/or the `-B` setting (if Git is incorrectly matching `a/b/foo.py` to `a/b/foo.py`). Other than that, you can try `git-imerge`, which (by doing incremental merges) can work with versions that are more-closely-related and hence match up easier: http://softwareswirl.blogspot.com/2013/05/git-incremental-merge.html – torek Dec 11 '16 at 22:36

1 Answers1

0

One woprkaround is to first make:

  • a temporary branch starting from the source branch of your merge
  • perform a series of git mv in order to manually transform the folders structure into the one seen in the destination branch
  • then merge the temporary refactored branch to your destination branch
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250