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?
Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.
Solution 2 Create two independent repositories, and push them to the same remote. Just use different branch names for each repo. Thanks a lot, that should be able to solve my problem. Actually, the two solutions use branchs to hold different projects.
Yes. You can put multiple projects in one Git repository but they would need to be on different branches within that repo.
Go to the repo where you want the other repo to be merged, and run the script. Now push the changes on the master branch to remote/origin.
extract lib/foo into a new project called common.
then include the full common project in both project 1 and 2
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).
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 :
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With