Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format-patch for a single file

Tags:

git

I have a file called test_module.c that has some differences that I want to apply to my local working copy.

I tried to create patch file from the remote by doing the following. However, git didn't complain about any errors. And didn't create any patch file either.

git format-patch master/dev_branch test/test_module.c

It is possible to create a patch of a single file, that I can apply?

(Using git version 1.7.5.4)

like image 636
ant2009 Avatar asked Oct 25 '11 05:10

ant2009


People also ask

How do I create a patch for one file?

You click on Actions->Create Patch... You click on "Working Copy Changes" You can now select all files that should be included into the patch file.

How do I format a patch in git?

In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.

What is a commit patch?

Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository.


2 Answers

If you give git format-patch a single revision, it will produce patches for each commit since that revision. If you see no output from that command, then I suspect that there were no changes to that file between origin/master and your current HEAD. As an alternative, you can provide a revision range (e.g. origin/master~3..origin/master) which covers the changes introduced to that file. Or, if the changes you want to produce a patch for are just contained in the single commit at the tip of origin/master, you can use the -1 parameter, as in:

git format-patch -1 origin/master test/test_module.c 
like image 195
Mark Longair Avatar answered Sep 23 '22 16:09

Mark Longair


You can use following syntax for creating patch for single file:

git format-patch [commit_hash] [file]
like image 38
Ondrej Slinták Avatar answered Sep 22 '22 16:09

Ondrej Slinták