2013-10-31 30 views
2

首先,我錯誤地將另一個回購源直接複製到一個更大的項目中,在一個子目錄中。自那時以來,原始的回購和子目錄都改變了。現在我有git-subtree的知識,我想將subdir作爲一個真正的子樹,以便我可以輕鬆地同步從原始回購的更改。如何使一個現有的子目錄作爲另一個git倉庫的子樹,用壓扁的提交?

我試過'git-subtree split',然後從最初的回購拉最新的來源,它只是工作。不過,我不希望整個歷史,但「--squash」的「分裂」沒有工作,這是我的命令

git subtree split -P xxx-dir --onto==1940032 
git remote add xxx https://github.com.... 
git fetch xxx 
git subtree pull -P xxx-dir xxx master 
# the pull worked, but whole history of xxx was imported too. '--squash' didn't work for above 'pull' 

git subtree merge -P xxx-dir xxx/master --squash 
# Can't squash-merge: 'xxx-dir' was never added. 

活像壁球僅適用於添加子樹而不是分裂。

有什麼想法?謝謝。

回答

0

關於:

git subtree pull -P xxx-dir xxx master 
# the pull worked, but whole history of xxx was imported too. '--squash' didn't work for above 'pull' 

看來你沒有使用--squash。或者你是否試圖說你再次嘗試過這個命令,而不是像你在這裏寫的那樣,用--squash? git subtree pull --squash -P xxx-dir xxx master

...和關於:

git subtree merge -P xxx-dir xxx/master --squash 
# Can't squash-merge: 'xxx-dir' was never added. 

你從運行哪個分支呢?看起來好像你正在試圖將你檢出的同一分支的變化合併到它自己的子文件夾中。由於該命令失敗,因此無法合併。我認爲這不是說壓扁是問題,而是恰好是失敗的壓扁合併。

1

我被git-subtreegit subtree merge

他們是不同的東西,但困惑也許git的子樹是一種有些git subtree merge stuff https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging

這是關於兩者之間的差異一個很好的答案包裝的:
What is the difference between git subtree merge and git-subtree

據我瞭解最容易做的,你是

什麼

1.刪除xxx-dir目錄,並提交更改

rm -r xxx-dir 
commit -am "xxx subtree" 

2.添加子樹

git subtree add --prefix=xxx-dir --squash xxx master 

缺點是,這樣做有3所提交更改的主要回購歷史:

  1. 刪除提交xxx-dir
  2. 提交「imp奧茨」有其歷史上的樹壓扁爲一個承諾
  3. 提交該合併的進口樹

據我理解這是一種混帳子樹的限制。

順便說一下,這應該是the source code of git-subtree也許有人比我更熟練可以挖掘它。

Ciao!

相關問題