简体   繁体   English

如何为新文件创建补丁?

[英]How to create patch for a new file?

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 . 假设我的文件驻留在名为TestDir的文件夹中。 Earlier TestDir did not have a file called entirelyNewfile.c , but now it is having the same. 此前TestDir没有一个名为entirelyNewfile.c ,但现在却具有相同。

How to create a patch for entirelyNewfile.c ? 如何创建一个补丁entirelyNewfile.c The idea is, the patch should get properly applied to the specs and generate the RPM build. 这个想法是,补丁应该适当地应用于规范并生成RPM构建。 With BUILD dir having this new file. 使用BUILD dir有这个新文件。

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 只是添加:如果我尝试在两个目录之间进行差异,一个具有新文件而另一个缺少相同的,为了创建补丁,它会生成错误,说该文件仅存在于一个文件夹中

-N添加到diff参数中。

diff /dev/null <newfile>

将为您的新文件创建一个补丁。

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,但类似的东西可以在任何其他版本控制系统中完成:

git init
git add .
git commit -m "initial state"
<do your edits here>
git add .
git commit -m "new state"
git diff HEAD^1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM