你可能想看看Git的submodule支持。子模塊可以讓你在另一個git倉庫中嵌入一個git倉庫。這類事情有alternative solutions,但我自己沒有用過。
一個例子可能是這樣的:
$ git clone git://github.com/username/project.git
$ cd project
$ git submodule add git://github.com/username/framework.git framework
$ git commit -m "added framework submodule"
如果您克隆與子模塊的存儲庫,您需要使用--recursive
選項:
$ git clone --recursive git://<repository-with-submodules>.git
或者,您可以定期克隆和然後運行:
$ git submodule init
$ git submodule update
閱讀鏈接文檔(和git submodule --help
)以獲取更多信息。
如果更改子模塊做,你帶他們進來是這樣的:
# first update the submodule just like any other git repository
$ cd project/framework
$ git pull
# now you have to record the new commit in the parent repository
$ cd ..
$ git commit -m "updated framework submodule"
的最後一步是必要的,因爲混帳保持特定犯了一個給定的子模塊相關的記錄(這樣,當任何人克隆父母,他們將獲得該子模塊的版本,而不是其最新版本,該版本可能會發生破壞性更改,從而阻止其按照預期與父庫一起工作)。因此,如果更新子模塊,則需要在父級中記錄新的提交。
如果您在framework
子模塊內進行了更改,您將再次使用git push
,就像您使用其他存儲庫一樣。然後您必須在父模塊中提交新版本。
完美,所以當對框架進行更改時,我該如何將它們拉入項目中,現在它已成爲模塊?另外,如果我對Framework進行更改而不是項目,那麼如何將這些更改回到Framework git庫中? – Justin 2012-04-26 00:23:21
我已經更新了我的答案。 – larsks 2012-04-26 00:25:58
一個小紙條。子模塊HEAD已分離,因此您需要小心在子模塊中進行更改。創建一個分支(或切換到分支),進行更改,提交然後推送。 – GoZoner 2012-04-26 03:10:32