Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
987 views
in Technique[技术] by (71.8m points)

git - format-patch for a single file

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...