Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
864 views
in Technique[技术] by (71.8m points)

git - Backport changes from renamed file

I have two branches: trunk, production. I have found a problem in trunk, made fix and committed it, pushed it. Now it was tested and I need do merge changes into the production branch as a hot-fix. I try to use the cherry-pick. However it doesn't work because a changed file(s) in the fix was renamed in the trunk earlier during some refactoring which I don't want bring into production.

I don't want merge everything, but take only this commit. The cherry pick fails with "deleted by us" conflict (of course, the new file never even existed in the production branch).

What is the correct way to bring the changes into the old file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If:

  • You expected/hoped that Git would detect the move or rename of the file on trunk, but it didn't, and
  • Your repository has a reasonable number of files

... then you should definitely consider changing your git config like this:

$ git config merge.renameLimit 999999

It is possible that during a merge/cherry-pick, git is hitting the default file check-limit (I think it's 400 or 1000 or something like that) before it is able to locate the suitable rename match. Upping this limit may cause merge/cherry-pick to take longer while it searches for your renamed file, but it can help avoid "deleted by us" merge-challenges.

That should do the trick, but if your renamed file was small and the changes between branches is significant, you might also play with the -X rename-threshold setting, e.g. lowering it from the default 50% with -X rename-threshold=25%.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...