How to create patch for a new file?
Solution 1
Add -N
to the diff
arguments.
Solution 2
diff /dev/null <newfile>
Will create a patch for your newfile.
Solution 3
The easiest way to do this that I know is to put all the files under version control (if they aren't already). I prefer Git, but something similar could be done in any other version control system:
git init
git add .
git commit -m "initial state"
<do your edits here>
git add .
git commit -m "new state"
git diff HEAD^1
Related videos on Youtube
RajSanpui
Around 9+ years experience into development C, C++, and Linux domain. Also understand Core-Java and consider it as a secondary skill. Currently, in addition to the developer responsibilities, i am also serving the role of DevOps engineer.
Updated on July 09, 2022Comments
-
RajSanpui almost 2 years
I know to create a patch for an existing file is easy:
diff -aru oldFile newFile 2>&1 | tee myPatch.patch
But what to do, if i want to create a patch for a totally new file? Assume my file is residing in a folder called
TestDir
. EarlierTestDir
did not have a file calledentirelyNewfile.c
, but now it is having the same.How to create a patch for
entirelyNewfile.c
? The idea is, the patch should get properly applied to the specs and generate the RPM build. With BUILD dir having this new file.Just to add: if i try to take diff between the two directories, one having the new file and the other missing the same, to create the patch, it generates an error saying that file is only present in one folder
-
RajSanpui about 13 yearsThanks a lot. But how to edit these? --- Olddir/testUsecase2.cc 1970-01-01 05:30:00.000000000 +0530 +++ NewDir/testUsecase2.cc 2011-04-11 20:39:56.000000000 +0530
-
RajSanpui about 13 yearsIf these are not properly formatted, these often leaves reject files during RPM builds.
-
RajSanpui about 13 yearsBut how will you create RPM builds from there? RPM build requires single patches to be added to SPEC file.
-
jcollie about 13 yearsThe "git diff" step will produce a patch that can be saved to a file and then added as a source to your RPM .spec file.