When you use git apply to apply a patch, and some hunks fail to apply, Git does not show which specific hunks failed by default. However, you can use the --reject option to save the rejected hunks to .rej files, which helps you identify which parts of the patch failed.
Use the --reject Option:
Run the following command to apply the patch and save rejected hunks to .rej files:
bashgit apply --reject <patch_file>
.rej files.Check the .rej Files:
.rej files in your working directory. These files will contain the hunks that failed to apply..rej file corresponds to a file in your repository and will show the context of the failed hunk.Review the Output:
bashgit apply --reject my_patch.patch
.rej files (e.g., file1.txt.rej, file2.txt.rej)..rej files to see the exact hunks that failed to apply.git apply --check to test if a patch applies cleanly before actually applying it.-v (verbose) flag:
bashgit apply -v --reject my_patch.patch
This approach ensures you can identify and manually resolve the failed hunks.