Git rebase with renamed files

I have a branch that renames many files, and I'm trying to reinstall it to master , where the source files were changed (preferably if this did not turn into a manual nightmare to resolve conflicts).

Situation

  • I ported a TypeScript JavaScript project to the local typescript branch. All .js files have now become .ts files, and some of the syntax has been updated.

  • Meanwhile, changes to the source .js files have occurred on the master branch.

  • I want to rebase the typescript branch to master - but the changes do not merge correctly, because file renames were not detected - conflicts that arise in which changes are made to the .js files that, according to git, were deleted (however, they were actually renamed to the file .ts ).

What I think I know

Git graph:

 o-[typescript] .js files become .ts | | o-[master] changes to the .js files | | | o |/ o-[root] common ancestor 

So, being in the root branch:

  • I can run this command to view all renames: git diff --name-status --find-renames=10% typescript

  • I understand that the Git merge command has the same functions --find-renames , although I have difficulty getting it to work.

    • Update: git merge -X find-renames=10% mybranch seems to be the expected syntax.
  • I understand that Git rebase can support find-renames , although I still don't understand how this is possible.

Ideas for a solution?

  • (Nope) Perhaps from root I could combine into typescript when detecting renames (for example: git merge -X find-renames=10% typescript ). Then root will be exactly the same as typescript , with the exception of renaming (and not bulk deletions / additions).

    • From there, I hope that I can just git rebase master , and with the renaming that was in place, the operation will go smoothly and put the changes into the correct files.
      • Update: I tried this, but my subsequent rebase did not go better than before.
  • (Yes) I think that perhaps the permutation itself should be done with the find-renames . I study this ...

    • git rebase -X find-renames=10% master - nope
    • git rebase -X --find-renames=10% master - nope
    • git rebase --find-renames=10% master - nope
    • git rebase -X recursive --find-renames=10% master - nope
    • git rebase --merge -X find-renames=10% master - nope
    • git rebase --strategy-option="rename-threshold=10" master - this ticket! it works!
  • (No) Perhaps I need to look at the problem differently? Maybe I should start with master , and then do some typescript squash merge with rename detection (and not with any kind of rebase?)

    • I don't need the typescript branch history, it will be crushed to one bold for viewing anyway.
    • Update: It seems that git stops working when trying this strategy. When I'm standing in the root branch, I can run git merge -X find-renames=10 typescript - and quickly -forwards to typescript .. (not quite what I was hoping for, I was hoping for a new commit that renamed, not added / removed ..)
      • When I stand in the master branch and I run the same command , git tells me the following: fatal: Unknown option for merge-recursive: -Xfind-renames=10 ...
      • Now it bothers me, because I didn’t actually enter what he quoted (I included a space), and the only thing that seems different to me is what branch I live in now, if the "Unknown" option then why does it work when in another branch?
      • In any case, so creepy and seems to make this approach dead end.
+7
git merge rebase
source share
2 answers

You can rebuild a branch when renaming is detected:

 git rebase --strategy-option="rename-threshold=10" master 

Edit: With Git 2.8.0, the term "rename-threshold" is deprecated in favor of "find-renames".

I am currently using Git 2.7.4, and therefore I could only verify that the above command worked in my case - you might need to use the term “find-rename” if the above command doesn’t work in your case your new version of git ...

In this example

  • the current branch is redistributed to master
  • 10% renaming threshold specified
  • changes in master to the source files will be placed in new (renamed) files (as opposed to a simple git rebase master ).
  • note how the syntax differs from the similar rename function found in the git diff , git log and git merge commands

The git rebase documentation is not very clear on this aspect of renaming. I thought I read in another command somewhere that the term “rename-threshold” was deprecated, although in this context, find-renames did not seem to work as a synonym, so if anyone knows of a better way to run the same commands, please specify so :)

+7
source share

This may help to first rename the file in the master branch first. This seems to be a pretty mechanical task that can be automated if necessary.

Then it will probably be quite easy to redistribute the typescript branch on top of it, since there will already be a common point. Some rebased typescript commits end up (almost) empty because their changes are already contained in master .

For this reason, you might want to merge typescript into master instead, in order to keep the original .js.ts change history intact.

-one
source share

All Articles