1

Suppose I have this folder structure:

/projectroot/foo/bar/subfoo/foo.txt

Now I change something in foo.txt a make a commit.

I have another repository with the exact same foo.txt but the folder structure is like this:

/projectroot/somedir/foo.txt

It's obvious that there should be a way to automatically apply the work on foo.txt in the second repository. I guess one can create a patch but I fail to find the right way to do it. I somehow need to create a patch out of the commit that works only on the file (or relative to the parent directory) and then apply it only to the file or to the directory that hosts the file.

How can I do this with git?

Christoph
  • 26,519
  • 28
  • 95
  • 133
  • Shouldn't you be able to get the diff between _current foo.txt_ and _previous foo.txt_ from git and apply it with _patch_? I've never used git, but in SVN it's trivial to get a diff file for: "_what has changed in file x between revisions r and n_". Maybe this post is telling you how to do the same thing with git: http://stackoverflow.com/questions/3368590/show-diff-between-commits – jahroy Sep 02 '12 at 19:08
  • Have a look at the `-p` parameter (strip prefix) of `patch` or `git apply` – knittl Sep 02 '12 at 19:21

1 Answers1

1

The usual thing to do is to create the patch as usual and then to use the options

--directory (and maybe also -p) when applying the patch with git apply or git am.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • Ok, this set me on the right track. I was able to get it to work after I googled the parameters you mentioned and then found this answer http://stackoverflow.com/a/11263899/288703 – Christoph Sep 02 '12 at 22:00