Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I instruct git diff NOT to batch together hunks that are near by?

Tags:

git

diff

Essentially, I would like git diff to return the same hunks as returned when I chose to split the hunks in an interactive rebase.

The command I am using is:

git diff -U3 -r -M

And it can produce something like this:

@@ -70,10 +70,10 @@
   "GetAllDeptJobs2": "None",
   "GetAllDeptJobsSlim": "None",
   "GetAllDirectDeposits": "Payroll (*)",
-  "GetAllEmployeeBenPlanElectedOptions": "None",
+  "GetAllEmployeeBenPlanElectedOptions": "Benefits (*)",
   "GetAllEmployeeConfidentialIdentifications": "HR (*)",
-  "GetAllEmployeeDeductionBenElectedRates": "None",
-  "GetAllEmployeeEarningBenElectedRates": "None",
+  "GetAllEmployeeDeductionBenElectedRates": "Benefits (*)",
+  "GetAllEmployeeEarningBenElectedRates": "Benefits (*)",
   "GetAllEmployeeElectedBenefitBeneficiary": "None",
   "GetAllEmployeeElectedBenefitBeneficiaryAndDependentData": "None",
   "GetAllEmployeeElectedBenefitBeneficiarySL": "None",

The relevant portion of the respective file (after the change is applied) is:

  "GetAllDeptJobs2": "None",
  "GetAllDeptJobsSlim": "None",
  "GetAllDirectDeposits": "Payroll (*)",
  "GetAllEmployeeBenPlanElectedOptions": "Benefits (*)",
  "GetAllEmployeeConfidentialIdentifications": "HR (*)",
  "GetAllEmployeeDeductionBenElectedRates": "Benefits (*)",
  "GetAllEmployeeEarningBenElectedRates": "Benefits (*)",
  "GetAllEmployeeElectedBenefitBeneficiary": "None",
  "GetAllEmployeeElectedBenefitBeneficiaryAndDependentData": "None",
  "GetAllEmployeeElectedBenefitBeneficiarySL": "None",

I would like to get a diff where these two hunks are split. I realize the trailing context of the first hunk overlaps with the delta of the second hunk, but so what? I would like to get the following two hunks instead:

@@ -70,7 +70,7 @@
   "GetAllDeptJobs2": "None",
   "GetAllDeptJobsSlim": "None",
   "GetAllDirectDeposits": "Payroll (*)",
-  "GetAllEmployeeBenPlanElectedOptions": "None",
+  "GetAllEmployeeBenPlanElectedOptions": "Benefits (*)",
   "GetAllEmployeeConfidentialIdentifications": "HR (*)",
   "GetAllEmployeeDeductionBenElectedRates": "None",
   "GetAllEmployeeEarningBenElectedRates": "None",

And

@@ -72,10 +72,10 @@
   "GetAllDirectDeposits": "Payroll (*)",
   "GetAllEmployeeBenPlanElectedOptions": "None",
   "GetAllEmployeeConfidentialIdentifications": "HR (*)",
-  "GetAllEmployeeDeductionBenElectedRates": "None",
-  "GetAllEmployeeEarningBenElectedRates": "None",
+  "GetAllEmployeeDeductionBenElectedRates": "Benefits (*)",
+  "GetAllEmployeeEarningBenElectedRates": "Benefits (*)",
   "GetAllEmployeeElectedBenefitBeneficiary": "None",
   "GetAllEmployeeElectedBenefitBeneficiaryAndDependentData": "None",
   "GetAllEmployeeElectedBenefitBeneficiarySL": "None",

I understand why git diff batched the two hunks, but is it still possible to get them separately and be able to apply the patch successfully?

like image 204
mark Avatar asked Dec 04 '25 10:12

mark


1 Answers

git diff -U0 seems to work for me (-U1 doesn't).

like image 55
mg979 Avatar answered Dec 07 '25 00:12

mg979



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!