Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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.

share|improve this question

closed as unclear what you're asking by jasonwryan, Zelda, Anthon, slm, rahmu Jan 16 '14 at 22:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2  
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. –  MattDMo Jan 16 '14 at 21:47
    
@MattDMo, I'm not patching against anything. All of the sources are new –  Amir Afghani Jan 16 '14 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 –  Amir Afghani Jan 16 '14 at 21:54

1 Answer 1

up vote 1 down vote accepted

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...

share|improve this answer
    
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 –  Amir Afghani Jan 16 '14 at 21:52
    
diff -Naur src2/ src > /tmp/mywork.patch that worked after I created an empty src2 directory. Accepting your answer –  Amir Afghani Jan 16 '14 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. –  janos Jan 16 '14 at 22:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.