Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a patch file from a diff of 2 folders

Tags:

git

diff

patch

I made some changes to an open source project without taking time to create proper patch files.

Now, the maintainer of the project released a new version, and among new and edited files, there are a bunch of renamed files.

What is the best way to apply my changes to the new version ?
I'm completely new to diff/patch use, and If I can get it done with git, it would be better.

like image 790
karatchov Avatar asked Mar 17 '10 07:03

karatchov


People also ask

How do I create a patch between two commits?

You can squash those commits into one commit using git rebase . After you have that one commit, you can use git format-patch to create the patch file of it.


2 Answers

If you have two directories a and b that are similar, and you want b to be the same as a, you can create and apply a patch with:

$ diff -ur b a > ba.diff $ patch -i ba.diff 

Suppose you have directories local (containing your local version of upstream1.0), upstream1.0, and upstream1.1. To create and apply your changes to upstream1.1:

$ diff -ur upstream1.0 local > my.diff $ cd upstream1.1 $ patch -i ../my.diff  

Check the documentation for patch, and try to convince the upstream maintainers to use git. Things will be much simpler if you can use git tools to work with your local repository.

like image 90
William Pursell Avatar answered Sep 20 '22 22:09

William Pursell


If the project is under git and you haven't committed your changes locally, you can simply do git diff > file.patch to get patchable diff data. If you have committed the changes locally, you can do git log to find the commit before you and than git diff commit_string > file.patch.

If the project isn't under git, or if you d/l source without cloning the repository (as the title suggests), you can use diff -urN original_dir new_dir > file.patch to create the patch file. In both cases you can try use patch later to apply the patch.

However, consider using git tools to merge your changes with the new version, since git is able to track filename changes too. You'll need to learn great deal about git itself, and it will take you some time to get it right - you should probably backup your work before starting to play with it.

like image 25
niry Avatar answered Sep 19 '22 22:09

niry