Multiple repositories in one directory (same level) - is it possible?

主宰稳场 提交于 2019-12-20 23:28:13

问题


My original problem is that I have a directory where I write various scripts. Each of them is independent of others, and usually one-file-long. I want to have some versioning applied to them, but I have the following problems/requirements:

  1. I don't want to have to store each small script in a separate directory!
  2. I don't want to store them all in one repository OTOH, as they are completely unrelated, and:
    • some of them may later grow to more files (and then they will need a separate dir),
    • I sometimes want to copy one of them to a different machine (and I want to clone the whole repo).
  3. I want to benefit from (distributed) version control mechanisms -- at least:
    • "infinite" number of revisions,
    • ability to clone repositories on different computers,
    • ability to do "atomic" multi-file commits.

Is it possible?
I'd prefer to do it in some mainstream distributed VCS (a solution using Mercurial would be preferable, but I'm not fixed).

EDIT: the solution has to be free (at least "as in beer") and cross-platform (at least Win32 & Linux).

Related, but didn't help:

  • "two-git-repositories-in-one-directory" -- didn't find it helpful: the accepted answer looks like point 2. (above) to me; the current "community voted" answer sounds like 1.
  • "Version control of single files using Subversion" -- also too much of 2. or 1.

回答1:


These requirements seem pretty "special" to me, so here is a solution on par with them ^^

You may use two completely different VCS, in the same directory. Even two "instances" of SVN might work: SVN stores its metadata in a directory called .SVN and has (for historical reasons regarding ASP) the option to use _SVN. The Directory listing should look like this

.SVN    // Metadata for rep1
_SVN    // Metadata for rep2
script1 // in rep1
script2 // in rep2
...

Of course, you will need to hide or ignore the foreign scripts or folders from each VCS...

Added: This only accounts for two scripts in one folder and needs one additional VCS per script beyond that, so if you even consider this route and need more repositories, rename each Metadir and use a script to rename it back before updating:

MOVE .SVN-script1 .SVN
svn update
MOVE .SVN .SVN-script1



回答2:


Why don't you simply create a separate branch (in the git sense) for each (group of) script(s)?

You can develop them individually as you please. Switching to a branch will show you only the scripts from that branch. It's sort of like directories but managed by the version control system. If you later want to pluck a branch out into another repository, you can do that and if you want to combine two scripts into a single project, you can do that as well. The copying them to the different machine point might be a problem but you can clone the branch you're interested in and you it should work for you.




回答3:


Another proposition for my own consideration is "Using Convert to Decompose Your Repository" article on hgtip.com. It fails as a "standalone" solution, but could be helpful as an addition to the "mv .hgN .hg / MOVE .SVN-script1 .SVN" idea.




回答4:


You can create multiple hidden repository directories and symlink .hg to whichever one you want to be active. So if you have two repositories, create directories for them:

.hg_production
.hg_staging

Then to activate either of them just do:

ln -sf .hg_production .hg

You could easily create a bash command to do this. So instead you could write something like activate-repo production, which would run ln -sf .hg_production .hg.

Note: Mac doesn't seem to support ln -sf so instead you'll need to do:

rm .hg; ln -s .hg_production .hg



回答5:


I can only think of these two lightweight versioning systems:

1) Using Dropbox with the Pack-Rat upgrade, to keep a full history of versions for each file automatically backed up and with the possibility to be shared with multiple Dropbox users: https://www.dropbox.com/help/113

If you have multiple machines managed by the same user (you), the synching would be automatic. Also if the machines are in the same LAN, Dropbox is smart enough to sync the files over the local network, so big files shouldn't be a worry.

2) Using a 'Versions' aware text editor for Mac OS X Lion. I'd expect TextMate, Coda and other popular Mac code editors to be updated to support this feature when Lion is released.




回答6:


How about a compromise between 1 and 2? Instead of a folder+repo for each script, can you bundle them into loosely related groups, such as "database", "backup", etc. and then make one folder+repo for each group? Then if you clone a repo on another machine, you're only pulling down a smaller number of unrelated files. (Is the bandwidth/drivespace really a concern?) To me, this sounds WAAAY simpler than all of the other suggestions so far.

(Technically this approach meets your requirements because (1) each script isn't in its own directory, (2) not all scripts are in the same repository, and (3) you can easily do this with any popular DVCS. :D)




回答7:


UPDATE (2016): Apparently, a guy named Cosmin Apreutesei created a tool named multigit, which seems to implement what I wished for in this question! If you ever read it, thanks a lot Cosmin! I've started using your tool this year and find it awesome.


I'm starting to think of some kind of an overlay over Mercurial/git/... which would keep a couple "disabled" repository meta-directories, let's say:

.hg1/
.hg2/
.hg3/

etc., and then on hg commit FILENAME would find the particular .hgN that is linked to FILENAME, and would then temporarily:

mv .hgN .hg
hg commit FILENAME
mv .hg .hgN

The main disadvantage is that it would require me to spend some time writing the tool. Or does anybody know of some ready-made one like this? If you do, please post as a full-featured answer (not a comment), I'm more than willing to accept it.



来源:https://stackoverflow.com/questions/5661059/multiple-repositories-in-one-directory-same-level-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!