[英]How to add new git repository file thru git patch
There are two Repositories: project-version-1 and project-version-2.有两个存储库:project-version-1 和 project-version-2。
project-version-1 dir has files: calculator/src/add.c calculator/src/subtract.c calculator/src/multiply.c and it does not have support for some feature (say division operation) project-version-1 dir has files: calculator/src/add.c calculator/src/subtract.c calculator/src/multiply.c and it does not have support for some feature (say division operation)
project-version-2 has the fix. project-version-2 已修复。 But the fix is on new file say calculator/src/division.c但修复是在新文件上说calculator/src/division.c
I have to provide the patch(fix) to project-version-1 from the project-version-2 git repository.我必须从 project-version-2 git 存储库向 project-version-1 提供补丁(修复)。 The patch should be a single diff file.补丁应该是一个单一的差异文件。 we can't ask the customer do "git add new-file" etc. how do i generate a patch for this?我们不能要求客户做“git add new-file”等。我如何为此生成补丁?
You can add the new file in your project-version-1
and you need to add the file by using the following commands:您可以在project-version-1
中添加新文件,您需要使用以下命令添加该文件:
git add -N division.c
This allows you to add an untracked file as your file is new.这允许您添加一个未跟踪的文件,因为您的文件是新文件。
And then add the modifications interactively by using然后使用交互式添加修改
git add -p
You will then obtain a console with the following message然后,您将获得一个控制台,其中包含以下消息
Stage this hunk [y,n,q,a,d,/,e,?]?
And then you may edit to see or directly stage the whole new file as it a new file.然后您可以编辑以查看或直接将整个新文件作为新文件暂存。 y
is for accepting to stage and e
for edit y
用于接受舞台, e
用于编辑
Then to check your changes, you may然后检查您的更改,您可以
git diff --cached
And if you are happy with your changes, you may then export it to a patch file by如果您对所做的更改感到满意,您可以通过以下方式将其导出到补丁文件中
git diff --cached > patch1.patch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.