Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update git mv index

Tags:

git

merge

Git doesn't track renames

I had a file dir1/some.class. I copied it as dir2/some.class and commited + pushed. Some weeks later, I've removed the dir1 version.

Can I teach git to act as if it was a move, rather than a new file?
So all changes to dir1/some.class that I will merge from other branches will actually merge into dir2/some.class ?

I tried with

git checkout mybranch
git config merge.renameLimit 100
git merge --no-ff -X rename-threshold=80 master
git config --unset merge.renameLimit

some of the files got merged. But some don't. Especially what I'm missing, is a git log ability, to see changes to dir2/class originated at the past as dir1/class, but that doesn't happen.

enter image description here

What actualy helped me was

Low renaming threshold (10% similarity to consider a file renamed)
Large merge.renameLimit ( consumes a lot of ram during merge )

 git checkout mybranch
 git config merge.renameLimit 999999
 git merge --no-ff -X rename-threshold=10 -Xignore-space-change master
 git config --unset merge.renameLimit

Also check out the answer marked below.

like image 835
Alex Avatar asked Mar 11 '26 05:03

Alex


1 Answers

I would try this: in the branch you're merging in, rename dir1 to dir2 (you can do this on a new, temporary branch if you want). Then merge that into your main branch.

like image 123
gcbenison Avatar answered Mar 12 '26 21:03

gcbenison