0

我在一个巨大的项目上工作,实际上只需要它的某些目录。所以我的项目看起来像:

project
 |- a/
 |- b/
 \- foo

但是,上游项目看起来像:

project
 |- a/
 |- b/
 |- c/
 |- foo
 \- bar

所以我在我的 .gitignore 中有:

c/
bar

但是,我现在正在尝试将上游重新定位到 master 上,并且我希望能够告诉 git 应该自动跳过应用于 bar、c/* 或 .gitignore 中的任何内容的补丁/块。但是,应该小心,更改 foo 和 bar 中的块的单个补丁仅应用于 foo 并在 bar 中忽略(不要只忽略整个补丁)。

有没有办法做到这一点?

4

2 回答 2

1

Git operates on "commit objects", not files / directories. Each commit object has an unique commit ID which is a hash of its previous commit id and the changes of that commit.

Which means that ignoring some files / directories would create a different commit ID - so it's basically equivalent to rebasing all the upstream changes, then creating a new commit which deletes all the files that you don't like.

You could probably do that locally with some scripts, but if you do that, every single commit in your local repository will be different from the version on the server, so you'd have to merge each time you pull new upstream changes / push something upstream.

Maybe you could convince the maintainers of the upstream project to split it into smaller submodules ?

于 2012-10-03T06:34:12.763 回答
0

对不起,我想你必须自己过滤。对此没有 git 命令。

通过导出来试试运气git format-patchdifffilter然后git am再做一次。

于 2012-10-03T07:54:41.840 回答