Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"git format-patch" equivalent for a single file?

Tags:

git

A collegue of mine forked my project and we want to incorporate his changed on a single file into my repo, keeping its history (mainly the commit logs).

The problem is that he clumsy in his commits so the commits contains diff from other files as well, unrelated to the project (or what need to be pulled into the original repo).

I would like to be able to do a "git format-patch" to extract the history, but only for a single file (or maybe two, the .cpp and .hpp files). I could not find an option to "format-patch" for this.

Is it possible?

Thanx!

like image 683
big_gie Avatar asked Dec 16 '10 16:12

big_gie


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 git patch file?

A patch is a text file whose contents are similar to Git diff but along with code it contains metadata about commits, for example, a patch file will include commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository.


1 Answers

Hum... So actually it's as simple as:

git format-patch commit_id file(s) 

where commit_id is the parent of the first commit to create a patch followed by the file or files wanted...

like image 71
big_gie Avatar answered Sep 24 '22 19:09

big_gie