Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply a .diff file

I got a .diff type file , seems like blew:

diff --git a/res/User.lua b/res/User.lua
index db8c2cc..4d2af0f 100644
--- a/res/User.lua
+++ b/res/User.lua
@@ -5,6 +5,7 @@ resetPassword = {}
+UserInfo = {}

Should i manually modify my local User.lua , or can i apply a diff file as like apply a patch file ? (or should convert a .diff file to .patch file, how to?)

would be thankful for any help.

like image 495
chengpei Avatar asked Jan 22 '14 05:01

chengpei


People also ask

How do I install a .diff file?

Applying a DIFF File in the Command LineCopy the DIFF files to the root directory of your store. Open the terminal on the server or access the server remotely via SSH. Replace /path/to/cscart/root/directory with the actual path to the root directory of your store. Replace example.

What opens a .diff file?

A DIFF file is a difference file, also called a PATCH file. Open one with Kompare, Mercurial, or a text editor like Notepad++.

How do I apply a git patch?

Applying a Patch If the user wants to check these changes are correct or not, so a different branch is created from the master and applied the patch to check the changes. This is how the patch is applied in the new branch. Applying is done by git apply 0001-Add-description. patch where “0001-Add-description.

How do I apply a diff patch in Windows?

Highlight your project to select it. From the main menu, select menu Tools -> Apply Diff Patch. In the resulting dialog, browse to your patch file, select it, and press the Patch button.


1 Answers

should convert a .diff file to .patch file, how to?

No, the extension isn't important. The content is.

You can try, and if doesn't work, fallback on this comment by Евгений Чорба (Evgeny Solis):

For those who has no patch command and git apply does nothing. The solution is:
Let's modify the patch file!

From

diff --git a/uc_attribute/uc_attribute.admin.inc b/uc_attribute/uc_attribute.admin.inc
index b9a978a..ef33ca3 100644
--- a/uc_attribute/uc_attribute.admin.inc
+++ b/uc_attribute/uc_attribute.admin.inc

To:

diff --git ubercart/uc_attribute/uc_attribute.admin.inc ubercart/uc_attribute/uc_attribute.admin.inc
index 1c35bf8..587fa67 100755
--- ubercart/uc_attribute/uc_attribute.admin.inc
+++ ubercart/uc_attribute/uc_attribute.admin.inc

Apply patch from project root using

git apply -p0 PATCHFILE.patch

Verbose:
You should replace 'a/' and 'b/' from patchfile with '<projectname>/' (In my example it is 'ubercart')

After applying patch you may see warning like

warning: ubercart/uc_attribute/uc_attribute.admin.inc has type 100755, expected 100644

It's OK, don't worry.

NOTE! If patch contains diffs for a several files you should replace ALL occurrences of 'a/<anypath>' and 'b/<anypath>'


Note: the OP chengpei has seen the other error message when using git apply:

  got a error: fatal: corrupt patch at line 7

It is documented in "“fatal: corrupt patch at line XX” when staging single line"

having newlines at the end of the file fixes it, and removing them causes it.


Magnus Bäck recommends in the comments:

Instead of editing the patch file to remove directory prefixes a/ and b/, run patch -p1 to have the first directory component stripped automatically.

tremby adds in the comments:

To produce a diff from git without the a/ and b/ prefixes you can use --no-prefix as an option to git diff

like image 91
VonC Avatar answered Sep 17 '22 11:09

VonC