Create a Patch file excluding some files

 ̄綄美尐妖づ 提交于 2019-12-10 20:30:56

问题


I want to create a patch file that will only patch certain files from dir2 to dir1. Both are git repos of the same project, however dir2 contains a modified highly modified version of the first. I want to only patch the changes made to certain files. dir2 also has extra files dir1 does not have. Mainly there are config files in dir1 I do not want dir2 to change, as these have changes that will break my local configuration. How can I exclude changing these particular files?


回答1:


To get the files which dir1 and dir2 share...

cd dir1
tree -aif --noreport > dir1.out
cd dir2
tree -aif --noreport > dir2.out
cat dir1.out dir2.out | sort | uniq -d > shared.out

(You can probably use ls to get the listing, but I can never get it right)

To get the changes to dir2 files which are also in dir1 since a given commit...

cd dir2
git diff <commit> -- `cat shared.out` > dir2.patch

Then apply that patch to dir1 using patch and the appropriate -p flag. Anything you don't want to change, use git checkout <dir1/somefile> to undo the changes. Then add and commit as normal.



来源:https://stackoverflow.com/questions/28096972/create-a-patch-file-excluding-some-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!