Git: include part of a project in another project

I have a rather difficult situation: in one project (git repo) I have a file and I need it in another project (another git repo). Is there any clear and (if possible) easy way to include it in my project? It looks like this:

git-repo-1: lib/foo lib/ololo git-repo-2: lib/*foo* (from repo-1) lib/bar lib/baz 

My question is: 1. How can I do this? 2. How can I update a file (from git-repo-1) to my repo (git-repo-2)?

ps Yes, I saw a lot of pages about subtrees, but ... it's still not so clear to me. Any suggestions? Even training ;-) I will be so grateful for everything.

UPD: What I want: http://git-scm.com/book/en/Git-Tools-Subtree-Merging BUT! I want to get only part of the rack storage in my repo project.

Question: how to separate the file that I need from one repo and merge it to another?

+7
git git-subtree
source share
4 answers

extract lib / foo into a new project called shared.
then include the full overall project in projects 1 and 2

+1
source share

I think you have two separate questions. First, how to include one repo in another (for which modules or subtree functions are intended). Secondly, how to use PART in the git repository.

I am not a git expert, but some of them were told that it is actually impossible to use only part of the repository - because of how git works, where a lot of history and changes are stored as "deltas" (therefore only parts of files that have been changed since one version to another, stored in a newer version ... or something like that).

So ... I think your best bet here is to put project 2 in a completely separate directory, and then copy only the files you need into your project 1. (Or set up some kind of symbolic / alias so you don't need to copy them) .

+1
source share

I do not recommend going deep into git. In my opinion, your project should be as clear as possible.

You can do the required work manually or using the script:

 cp path/to/git-repo-1/lib/foo path/to/git-repo-2/lib/ git add . git commit -a -m 'updated lib/foo' 
0
source share

I'm afraid you cannot include only part of another repository. To solve this problem, I have a small script that checks the latest version of the file I need in the current working directory. If you use "git archive", you can get the latest version from the upstream:

For example:

 git archive --format=tar --remote ssh:// git@gitserver :7999/infra/scripts.git HEAD supplier.csv | tar xf - git add ./supplier.csv ; git commit -m 'Update suppliers from upstream' 
0
source share

All Articles