How can I create / apply git fixes only for commits that modify certain files

I have two git repositories that are forked of each other, and I sometimes need to import commits from one to the other.

For instance:

git-repo1 has this directory structure:

repo1/project1/src

repo1/project2/src

while git-repo2has the following directory structure:

repo2/src/

I would like to make a series of commits and create patches only for repo1/project1/srccommits that modify files in a specific subdirectory (say ), and ignore all commits that only modify files elsewhere.

Or, alternatively, generate patches for all commits, but apply only patch if it modifies files in a specific directory.

, git diff .

git .

?

Update1

( git ?) .

, , ? .

+5
2

git rev-list --reverse series -- repo1/project1/src/ \
| xargs -I@ git format-patch --stdout @^! >mystuff.patch

, mystuff.patch

cat >mystuff.sed <<\EOD
/^(From [0-9a-f]{40}|diff --git )/!{H;$!d}
x
/^From /b
${h;s,.*--,--,;x}
\,^diff[^\n]* [ab]/repo1/project1/src/,!{$!d;x;b}
${p;x}
EOD

sed -Ef mystuff.sed mystuff.patch >justmystuff.patch

.

git am justmystuff.patch

-p n --directory=new/path/to .

(: EOD → \EOD, )

+9

( , -), .

( )

A,

 $ git checkout repoA/master
 $ git log sub/dir/ectory
 a34256f ...

- B

 git checkout repoB/master
 git cherry-pick a34256f
+1

All Articles