Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backport changes from renamed file

Tags:

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?

like image 923
kan Avatar asked Mar 19 '12 15:03

kan


People also ask

How does git know a file changed?

For every tracked file, Git records information such as its size, creation time and last modification time in a file known as the index. To determine whether a file has changed, Git compares its current stats with those cached in the index. If they match, then Git can skip reading the file again.

How do I edit a cherry pick commit message?

To change the commit message when cherry-picking, use “git cherry-pick” with the “-e” option. As illustrated in this example, your default editor will open and it will let you change the commit message. When you are satisfied with the edits, save your file and your commit message should be saved successfully.


2 Answers

I'd use good old patch for this:

git show COMMIT_ID -- old/file/name.txt | patch new/file/name.txt 
like image 44
robinst Avatar answered Oct 20 '22 04:10

robinst


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%.

like image 53
javabrett Avatar answered Oct 20 '22 05:10

javabrett