9

I have a quite 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 (as it possible) simple way to put it into my project? It's looks like:

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 it? 2. How can I update the file (inc. from git-repo-1) into my repo (git-repo-2)?

p.s. Yes, a saw many pages about subtrees, but... it still not so clear for me. Any suggestions? Even instruction ;-) I'll be so appreciate for anything.

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

The question is: how to split off the file I need from one repo and merge it to another?

5
  • 1
    Try using submodules? Commented Sep 20, 2013 at 9:12
  • I can't understand how. Can you help me? Commented Sep 20, 2013 at 9:16
  • possible duplicate of How to set up a git project to use an external repo submodule? Commented Sep 20, 2013 at 10:32
  • Just use file:///path/to/your/git-repo-1 as the remote URL, it'll do the trick. A little Googling would probably help, too ;) Commented Sep 20, 2013 at 10:34
  • 2
    Thanks, but this is not exactly what I want: partial including one repo into another or including part of one repo into another. Commented Sep 20, 2013 at 11:55

4 Answers 4

2

extract lib/foo into a new project called common.
then include the full common project in both project 1 and 2

Sign up to request clarification or add additional context in comments.

1 Comment

This is the proper way to do it as it minimises the dependency management overhead.
1

I think you have two separate questions here. The first is how to include one repo in another (which the modules or subtree features are for). The second is how to only use PART of a git repo.

I am not a git expert, but have been told by some of them that it is not really possible to only utilize portions of a repository -- because of how git works, where a lot of history and changes are stored as "deltas" (so only the portions of files that changed from one version to another are stored in a newer version... or something like that).

So... I think your best bet here is to bring down project 2 in a totally separate directory, then copy just the files you need out of there into your project 1. (Or set up some kind of symlink / alias thing so you don't have to copy them).

Comments

1

I fear you can't include only a part of another repository in yours. To deal with that problem, I have a small script that checks out the latest version of the file I need into the current working directory. If you use "git archive", you can retrieve the latest version from 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'

Comments

-1

I do not recommend to go deeply in git. In my opinion, your project must be as clear as possible.

You can do the job you need manually or using script:

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

1 Comment

Unfortunately this is impossible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.