I'm working on an R project which currently has the following directory layout:
proj1 |-- file.r
file.r
is used to build a statistical model specific to Project 1 (hence proj1
).
During the course of development, we will be building numerous models for numerous projects:
Work |-- proj1 | └-- file.r |-- proj2 | └-- file.r : └-- projn └-- file.r
file.r
will be 90% similar between each of the projects, but there will be differences. My question is, is there a way to create a master file.r
file and simply fork it for each project? That way, a bugfix/enhancement to the master can simply be rebased down to the forks, and the file-specific changes will be simply applied on top. My first thought was to use submodules, but I'm not certain how to apply that here. Thanks!
Use a "topic branch" for each project:
git checkout master
git add file.r ;# this is your master template upon which others are based
git commit -m "Committed the master file"
Then for each project:
git checkout -B <project> master ;# create and checkout <project> branch
<hack away on file.r, commit when you want>
git push origin <project> ;# to share <project> with others
So in practice you end up with master
, upon which, say, project1
, project2
, project3
and so forth are based. Should do exactly what you want and keep it all quite sane.
Advantages of this solution over others that encourage multiple repositories:
file.r
with git diff projectA projectB -- file.r
. You could do the same with multiple repositories, but it requires a repository specification like git diff projectA/master projectB/master -- file.r
. Could get confusing if you have 20-30 project repositories or use submodules. git fetch origin
and watching the output. git remote add <project>
repositories until you've got them all. Disadvantages (an incomplete list):
file.r
you're viewing at any given moment. That might be a deal breaker. I dunno. I suppose it depends on your workflow. R
projects, however, this might be less of a concern. IMO the best way to achieve this is:
git submodule
to integrate the shared code to each project There are ways described in the other answers.
For example,
Finally, when no other way, I use comments in the file header, that it is a fork of another file.
Date | Author | Description ------------- | ------------------- | -------------- 05/18/2018 | You | Forked from Other/file.r
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.