A colleague sent me a patch from his git repo. Since it’s not a clone, his index entry contains hashes that are not known in my repo. Sample:
index 20589f5..bbdd152 100644
20589f5 exists in his repo but not in mine.
When I try to apply the patch using TortoiseMerge, I get the message
fatal: not a valid object name
How could I trick TortoiseMerge into accepting the patch?
Edit: It doesn’t have to be TortioseMerge. Any other tool that lets me apply my patch visually (and runs on Windows, preferably free) is good too.
Since it is from a colleague, the best answer is to simply have him provide the missing data, either via a patch series or by letting you fetch from his repository. If you can get this data, any other route is just a waste of time.
Otherwise, you have have a patch that does not apply cleanly to your current work tree, and you don’t have enough information to perform a 3-way merge.
Now, if you want to try applying the patch anyway, I suggest using
git am(orgit apply, if he provided a diff instead of a patch — which is bad practice) to attempt to apply the patch. You can use the--rejectoption to force it to be applied as much as possible. Git will create `.rej’ files for diff hunks that did not apply cleanly to your current tree. You can then go and attempt to apply these manually.Another option is to simply manually apply the entire patch via your editor.
There is no need to use
patchas suggested elsewhere.git applywill always be preferable.Now, you want to do this visually, and the best suggestion I can offer is the pseudo-visual
--interactivemode ofgit apply. This will allow you to apply the patch hunk by hunk.You can’t do this with Tortoisemerge because Tortoisemerge is expecting two or three complete files in order to perform the merge. Since your index values don’t correspond to known blobs in your repository, you can’t provide the complete base file revision to Tortoisemerge.