1

There are two Repositories : project-version-1 and project-version-2.

  1. 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)

  2. project-version-2 has the fix. But the fix is on new file say calculator/src/division.c

Problem :

I have to provide the patch(fix) to project-version-1 from the project-version-2 git repository. 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 ?

jeshmal4u
  • 41
  • 3

1 Answers1

1

You can add the new file in your project-version-1 and you need to add the file by using the following commands:

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

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
Pat. ANDRIA
  • 2,330
  • 1
  • 13
  • 27