簡體   English   中英

如何在我的git項目中包含外部svn存儲庫?

[英]How do I include a external svn repository in my git project?

我正在使用git作為項目的修訂控制軟件。 我的項目需要使用第三方代碼庫,它使用SVN作為其修訂控制軟件。 (在這種情況下,第三方代碼是一個名為Yii的PHP框架,而不是它與問題非常相關)。

有沒有辦法在git中設置外部依賴,可以幫助從外部SVN存儲庫中提取代碼並使其保持最新?

如果我的項目使用的是SVN,那么設置起來會很簡單,因為我會這樣做:

> svn propset svn:externals yii-1.1.6 https://yii.googlecode.com/svn/tags/1.1.6/framework

...然后,每當我執行svn checkout (或svn update )時,我都會將yii代碼庫吸收到名為“ yii-1.1.6 ”的本地文件夾中。 我可以在git中做類似的事情嗎? 有沒有人在我可以復制的公共github倉庫中有一個例子? 我敢肯定它一定是常見的需求嗎?

您可以對svn repo執行git-svn克隆,然后將該repo包含到主Git倉庫中,並將其聲明為子模塊

簡單地記住: git子模塊與svn子模塊不兼容 ,因為他們總是引用固定版本。 看到:


但是,正如我在“ git submodule tracking latest ”中提到的,你可以從git 1.8.2(2013年3月)開始通過子模塊跟蹤最新的repo分支

$ git submodule add -b <branch> <repository> [<path>]
$ git submodule update --remote ...

您也可以通過SVN將第三方庫簽出到您的樹中,然后將它添加到您的主項目中(包括所有.svn子目錄)。

有點臟,但也簡單明了。

當你需要更新時,只需要svn update和git commit。

我的工作情況完全相同。 我使用SmartGit。 我在Git存儲庫根目錄中提交了.gitsvnextmodules文件(提交給Git)。

[submodule "anyString"]
        path = path/to/svn/submodule
        url = https://url.of.svn/repository/blah
        revision = 1234
        branch = branches/branch #or it can be "trunk"
        fetch = trunk:refs/remotes/svn/trunk
        branches = branches/*:refs/remotes/svn/*
        tags = tags/*:refs/remote-tags/svn/*
        remote = svn
        type = dir

SmartGit將其顯示為在修訂版1234處指向“h​​ttps://url.of.svn/repository/blah/branches/branch”(url +分支值連接)的子模塊(如果未指定,則使用HEAD修訂版)。 fetch + branches + tags就像.git / config規范。

如果您不想快速切換第三方項目的分支(我這樣做,因為我也想提交子模塊),請使用類似的東西。

[submodule "alternativeSubmodule"]
        path = path/to/svn/submodule
        url = https://url.of.svn/repository/blah/branches/branch
        revision = 1234
        branch = /
        fetch = :refs/remotes/svn/git-svn
        remote = svn
        type = dir

.gitsvnextmodules 規范中的更多細節。

對於這種配置,SmartGit與子模塊的工作方式與通常的Git子模塊一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM