Home > database >  Apply a git patch to a series of renamed files
Apply a git patch to a series of renamed files

Time:10-07

I have created a patch which modifies a series of files, as well as adds some new ones.

I am attempting to apply this patch on a older release branch, but it fails due to the modified files not existing in tree.

(Extract of some of the errors)

error: polyglot/java.hh: does not exist in index
error: polyglot/v7.hh: does not exist in index

This is because the modified files were renamed from .h to .hh in a commit not present on the older release branch.

How do I apply this patch, given that I am modifying files ending in .hh but the tree contains those files with .h endings?

CodePudding user response:

Try applying it on top of a newer commit where it can be applied (not necessarily newer, it can be older, whatever allows you to apply the patch) and then cherry-pick the resulting commit on top of the revision you really want. So... something like

git checkout -b temp <one-commit--or-branch-that-allows-the-patch-to-be-applied>
git apply some-patch
git add .
git commit -m "Here's a patch I need to be applied"
git checkout <where-i-really-want-it-applied>
git cherry-pick temp

That should work.

CodePudding user response:

the hacky but imho quickest way : edit the file names in your patch file

# change this line :
diff --git a/polyglot/java.hh b/polyglot/java.hh
# to :
diff --git a/polyglot/java.h b/polyglot/java.h
  •  Tags:  
  • git
  • Related