Is there an GIT alternative for SVN Externals?

时光怂恿深爱的人放手 提交于 2019-12-11 11:11:20

问题


I currently use SVN to manage jboss server configurations and i need to have several copies of the same sub-directory in each working copy, but referencing the same directory on the server so that when i change some file, every copy gets the update.

Example:

  • /server/bin (shared)
  • /server/node-01 (copy of repository /server/node)
  • /server/node-02 (copy of repository /server/node)

Is it possible to achieve the same using git? I could not find a definitive answer in the (maney) similar questions.


回答1:


The best approximate I know of is git-submodule [1].

You can define sub-repositories and have the "parent" repository conceptually contain a hash specifying the exact revision each sub-repository should have.

When your HEAD moves in the sub-repository, "git status" and "git diff" will report that as a hash change in the parent repo.

Unfortunately, git submodules are a bit clunky:

  • When you pull in the parent repo, it will not automatically update the child repos. Instead, the child repos will appear as though you've made local changes (that revert their new position back to where they were).

  • You have to explicitly call "git submodule update" every time (or script it, of course) after you pull/merge the parent repo.

This also means that "git rebase" and other operations on the parent do not work as well in the presence of submodules. But you do have fine-grained control over the behavior here, so there's nothing you cannot work around.

[1] http://kernel.org/pub/software/scm/git/docs/git-submodule.html



来源:https://stackoverflow.com/questions/6681459/is-there-an-git-alternative-for-svn-externals

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