RubyTuesdayDONO
RubyTuesdayDONO

Reputation: 2378

diff for patching without renaming target file

how do i create a standard patch using diff -u without using a different name for the "new" file?

when i submitted a patch for an Apache project, the committer advised that i don't need to rename the file when submitting patches. i can somewhat understand how this breaks patching since the name of the "new" file should somehow match the name of the patch target - however they can't be in the same directory with the same name.

is it okay (for ease of patching) to rename the "old" file, such that i should have used:

diff -u Source-old.java Source.java

instead of:

diff -u Source.java Source-new.java

?

Upvotes: 1

Views: 1492

Answers (1)

michael
michael

Reputation: 9809

Given an existing project 'a', copy whole project to 'b', make changes in 'b'. Generate diff between original directory and your copied directory.

E.g., checkout or download project to directory 'a', copy to 'b':

$ tree a
a
`-- dir
    |-- Bar.java
    `-- Foo.java

$ cp -r a b 

$ tree b
b
`-- dir
    |-- Bar.java
    `-- Foo.java

Make changes to 'b' (and only 'b'):

$ diff -r -s a b
Files a/dir/Bar.java and b/dir/Bar.java are identical
Files a/dir/Foo.java and b/dir/Foo.java are identical

$ sed -i  's/Foo.*$/& \/* Change...*\//' b/dir/Foo.java 

$ diff -ruN  a b  | tee a.patch
diff -ruN a/dir/Foo.java b/dir/Foo.java
--- a/dir/Foo.java  2012-08-02 18:41:39.444720785 -0700
+++ b/dir/Foo.java  2012-08-02 18:46:45.319932802 -0700
@@ -1,2 +1,2 @@
 package dir;
-public class Foo {}
+public class Foo {} /* Change...*/

$ gzip a.patch

Another alternative is to store the original source in a temporary, local git repository, then use git's built-in diff to generate the patch. Or, better, if the original source is using git, then just clone the repo and work directly in the source tree itself, and (still) using git to generate the patch.

Upvotes: 1

Related Questions