简体   繁体   中英

How to push shared files (header/source) from outside a Git repository to it?

I've developed two small programs, both of which include my_lcd_lib.h and my_lcd_lib.c . To prevent code duplication I moved this "lib" from the include folder in each project to /usr/local/include . So far, so good.

How could I tell Git to include those files when pushing the repo? So the repos from Prog1 and Prog2 would have their own copies of the header/source files.

I can imagine three ways:

  1. When pushing the program repo from dev pc to gitlab server, git could include those outside files by some tricks. Maybe need to edit some .git* files?

  2. I could make a lib-repo for the stuff in /usr/local/include . I could set up my program repo to load the appropriate files from the lib-repo. Is that what the pipe/cli are meant for?

  3. I could copy the header files from /usr/local/include to the program repo just before pushing the program repo. This looks very unsexy.

No, you cannot push files outside the repository. Git does not push individual files, it pushes commits. The files have to part of a commit.

Once you've committed those files in your repository, the rough solution is to symlink them into /usr/local/include/ . The better solution is to used a build tool like autoconf and install them in /usr/local/include .

Git is not a substitute for a build tool, nor dependency manager, nor installer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM