Linux 如何为新文件创建补丁?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5623727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create patch for a new file?
提问by kingsmasher1
I know to create a patch for an existing file is easy:
我知道为现有文件创建补丁很容易:
diff -aru oldFile newFile 2>&1 | tee myPatch.patch
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.
但是如果我想为一个全新的文件创建一个补丁怎么办?假设我的文件驻留在名为TestDir
. 之前TestDir
没有名为 的文件entirelyNewfile.c
,但现在它具有相同的文件。
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.
如何创建补丁entirelyNewfile.c
?这个想法是,补丁应该正确应用于规范并生成 RPM 构建。有了这个新文件的 BUILD 目录。
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
只是补充一下:如果我尝试在两个目录之间进行差异,一个有新文件,另一个缺少相同的文件,以创建补丁,它会生成一个错误,指出该文件仅存在于一个文件夹中
采纳答案by Ignacio Vazquez-Abrams
Add -N
to the diff
arguments.
添加-N
到diff
参数。
回答by jcollie
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
回答by Veerendra C
diff /dev/null <newfile>
Will create a patch for your newfile.
将为您的新文件创建补丁。