How to create patch for a new file?

20,558

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
Share:
20,558

Related videos on Youtube

RajSanpui
Author by

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, 2022

Comments

  • RajSanpui
    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. Earlier TestDir did not have a file called entirelyNewfile.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
    RajSanpui about 13 years
    Thanks 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
    RajSanpui about 13 years
    If these are not properly formatted, these often leaves reject files during RPM builds.
  • RajSanpui
    RajSanpui about 13 years
    But how will you create RPM builds from there? RPM build requires single patches to be added to SPEC file.
  • jcollie
    jcollie about 13 years
    The "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.

Related