创建不包含某些文件的补丁文件 [英] Create a Patch file excluding some files
问题描述
我想创建一个补丁文件,仅将某些文件从dir2修补到dir1。两者都是同一项目的git repos,但是dir2包含第一个的修改后的高度修改版本。我只想修补对某些文件所做的更改。 dir2也有dir1没有的多余文件。
主要是dir1中有一些配置文件,我不希望dir2更改,因为这些文件中的更改会破坏我的本地配置。我该如何排除更改这些特定文件的问题?
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?
推荐答案
要获取dir1和dir2共享的文件...
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
(您可以使用 ls
以获得列表,但我永远无法正确找到它)
(You can probably use ls
to get the listing, but I can never get it right)
要获取对dir2文件的更改,这些文件自给定提交后也位于dir1中... > p>
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
然后使用 patch $ c将补丁应用到dir1 $ c>和相应的
-p
标志。如果您不想更改任何内容,请使用 git checkout< dir1 / somefile>
撤消更改。然后像往常一样添加并提交。
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.
这篇关于创建不包含某些文件的补丁文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!