1

I am trying to do a mini code review for new source code that I have in a folder. The code is not in any kind of version control. Is it possible to create a patch file from this so I can post it for review?

Every incantation of patch I've seen fits an oldCode/newCode pattern.

4
  • 3
    What are you patching against? If you're making changes to a file, save it as a new file and then run patch from there. Commented Jan 16, 2014 at 21:47
  • @MattDMo, I'm not patching against anything. All of the sources are new Commented Jan 16, 2014 at 21:51
  • Let me provide more context. When I put the code up for review, all of the files will show up as new source Commented Jan 16, 2014 at 21:54
  • If they are new files, they are new files; there is no (useful) difference to before (unless you diff against /dev/null, but that is rather pointless anyway) Commented Oct 7, 2015 at 16:19

1 Answer 1

1

If I understand correctly, and given that you want to include your new src directory in the patch, you could call diff -Naur with a non-existent (or empty) directory as the first parameter:

diff -Naur nonexistent src > src.patch

However, when using this patch file, for example with patch -p0 < src.patch, the files will be extracted in a directory named "nonexistent".

To make it easier for the receiver, perhaps you could temporarily rename your src dir to something else, for example:

mv src src-real
diff -Naur src src-real > src.patch
mv src-real src

I don't know if there is a better way...

3
  • thanks for your response. This didn't quite work for me. I get: diff -u /dev/null src/ > code.patch diff: src/null: No such file or directory Commented Jan 16, 2014 at 21:52
  • diff -Naur src2/ src > /tmp/mywork.patch that worked after I created an empty src2 directory. Accepting your answer Commented Jan 16, 2014 at 22:00
  • @AmirAfghani I improved my answer. See my last word of caution, about what happens when using such patch file. And maybe unaccept the answer for a while, maybe others will answer it better. You can accept a few days later if it still makes sense. Commented Jan 16, 2014 at 22:09

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.