git: symlink/reference to a file in an external repository -
is possible in git have "link" particular file in git repo? git submodules folders question particular file, not full directory:
my-project/ class1.java class2.java logback.xml (link particular file, https://github.com/thehilikus/jrobocom/blob/master/jrobocom-core/src/main/resources/logback.xml)
so can seen, in case doesn't make sense have whole submodule folder, 1 file.
i'm ok link being locked particular commit better if it's moving changes in own project's lifecycle
as note, has nothing file-system's symbolic links; i'm talking reference file in project, repo, branch, or anything. it's ok if content of file duplicate , not file-system symlink
git has features can use achieve need. supports file system symlinks , supports submodules. submodules standard way handle references other repositories. can use them in conjunction way reference files locally. can handled directly using relative symbolic links or indirectly using script copies on files submodule need them.
you should have 1 submodule per external git tree , should treat submodules care, not links external repositories specific commits. following solutions show how use individual files external repostiory still maintain advantages of submodules.
an alternative way fetch files directly lose advantage of submodules entirely or have build features yourself. stated, submodules standard way handle sort of task , should use unless have special needs avoid downloading other files @ cost.
using submodule , symlink
once have submodule ready, can add filesystem symlinks pointing submodule directory structure.
run in shell in project directory:
$ git submodule add https://github.com/thehilikus/jrobocom $ ln -s jrobocom/jrobocom-core/src/main/resources/logback.xml $ git add .gitmodules logback.xml $ git commit -m "add symbolic link logback.xml respective submodule"
now have symlink:
logback.xml -> jrobocom/jrobocom-core/src/main/resources/logback.xml
using submodule , script
as alternative, can use custom scripts copy on ordinary files submodules. in special cases handle external repositories script without submodules not recommend it.
create file bootstrap.sh
containing:
#!/bin/sh git submodule init git submodule update cp jrobocom/jrobocom-core/src/main/resources/logback.xml .
run in shell in project directory:
$ git submodule add https://github.com/thehilikus/jrobocom $ git add .gitmodules bootstrap.sh $ git commit -m "add script fetch logback.xml respective submodule"
note not adding logback.xml
file git, fetched submodule.
instruct users of repository first run script above. prepare repositories using submodules, fetch submodule data , copy file location. there's sort of bootstrap script in project.
using script fetch single file via git protocol
found solution git >= 1.7.9.5 using git archive
.
create file bootstrap.sh containing:
#!/bin/sh git archive --remote=https://github.com/thehilikus/jrobocom master:jrobocom/jrobocom-core/src/main/resources logback.xml | tar -x
run in shell in project directory:
$ git add bootstrap.sh $ git commit -m "add script fetch logback.xml directly remote project"
using script fetch single file via http
if repository hosting service serves individual files via http, can use curl
or wget
download them.
create file bootstrap.sh containing:
#!/bin/sh curl -o https://raw.githubusercontent.com/thehilikus/jrobocom/master/jrobocom-core/src/main/resources/logback.xml
run in shell in project directory:
$ git add bootstrap.sh $ git commit -m "add script fetch logback.xml directly github"
notes on scripts fetching single files
you store references in files specific extention (like *.url
) or maintain list of references in 1 file (like .references
in project directory) , build more comprehensive script goes through references , downloads respective files.
Comments
Post a Comment