簡體   English   中英

SVN:外部相當於Git?

[英]SVN:externals equivalent in Git?

我使用svn:externals從另一個SVN存儲庫中使用了兩個SVN項目。

我怎樣才能在Git中擁有相同的存儲庫布局結構?

Git有兩種類似的方法,但不完全等同於svn:externals:

  • 子樹合並將外部項目的代碼插入到repo中的單獨子目錄中。 這有一個詳細的設置過程 ,然后對其他用戶來說非常容易,因為在檢出或克隆存儲庫時會自動包含它。 這可以是在項目中包含依賴項的便捷方式。
    從其他項目中提取更改很容易,但提交更改很復雜。 如果另一個項目必須從您的代碼合並,項目歷史將合並,兩個項目實際上成為一個。

  • Git子模塊手動 )鏈接到另一個項目的存儲庫中的特定提交,就像帶有-r參數的svn:externals一樣。 子模塊易於設置,但所有用戶都必須管理子模塊,子模塊不會自動包含在結帳(或克隆)中。
    盡管將更改提交回其他項目很容易,但如果更改了repo,這樣做可能會導致問題。 因此,將更改提交回正在開發的項目通常是不合適的。

正如我在“ Git子模塊新版本更新 ”中提到的,您可以使用Git 1.8.2子模塊實現相同的SVN外部功能

git config -f .gitmodules submodule.<path>.branch <branch>

這足以使子模塊跟隨分支(如子模塊上游repo的遠程分支的LATEST提交)。 你需要做的就是:

git submodule update --remote

這將更新子模塊。

更多細節在“ git submodule tracking latest ”中。

要將現有子模塊轉換為跟蹤分支的一個子模塊 :請參閱“ Git子模塊:指定分支/標記 ”中的所有步驟。

我是gil(git links)工具的作者

我有一個替代解決方案的問題 - gil(git links)工具

它允許描述和管理復雜的git存儲庫依賴項。

它還提供了git遞歸子模塊依賴性問題的解決方案

考慮您有以下項目依賴項: 示例git存儲庫依賴關系圖

然后,您可以使用存儲庫關系描述定義.gitlinks文件:

# Projects
CppBenchmark CppBenchmark https://github.com/chronoxor/CppBenchmark.git master
CppCommon CppCommon https://github.com/chronoxor/CppCommon.git master
CppLogging CppLogging https://github.com/chronoxor/CppLogging.git master

# Modules
Catch2 modules/Catch2 https://github.com/catchorg/Catch2.git master
cpp-optparse modules/cpp-optparse https://github.com/weisslj/cpp-optparse.git master
fmt modules/fmt https://github.com/fmtlib/fmt.git master
HdrHistogram modules/HdrHistogram https://github.com/HdrHistogram/HdrHistogram_c.git master
zlib modules/zlib https://github.com/madler/zlib.git master

# Scripts
build scripts/build https://github.com/chronoxor/CppBuildScripts.git master
cmake scripts/cmake https://github.com/chronoxor/CppCMakeScripts.git master

每行以下列格式描述git鏈接:

  1. 存儲庫的唯一名稱
  2. 存儲庫的相對路徑(從.gitlinks文件的路徑開始)
  3. Git倉庫將用於git clone命令Repository branch to checkout
  4. 以#開頭的空行或行未被解析(視為注釋)。

最后,您必須更新根示例存儲庫:

# Clone and link all git links dependencies from .gitlinks file
gil clone
gil link

# The same result with a single command
gil update

結果,您將克隆所有必需的項目並以適當的方式將它們相互鏈接。

如果要使用子鏈接存儲庫中的所有更改在某個存儲庫中提交所有更改,則可以使用單個命令執行此操作:

gil commit -a -m "Some big update"

Pull,push命令以類似的方式工作:

gil pull
gil push

Gil(git links)工具支持以下命令:

usage: gil command arguments
Supported commands:
    help - show this help
    context - command will show the current git link context of the current directory
    clone - clone all repositories that are missed in the current context
    link - link all repositories that are missed in the current context
    update - clone and link in a single operation
    pull - pull all repositories in the current directory
    push - push all repositories in the current directory
    commit - commit all repositories in the current directory

更多關於git遞歸子模塊的依賴問題

暫無
暫無

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

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