2017-07-10 38 views
0

我有很多git代碼庫,我想:Synching 2個ancestraly相關Git倉庫忽略一些提交

  1. 端口到一個新的Git服務器。
  2. 向它們添加子模塊。

這是它自己的將是直截了當的,事情是,我想逐步做到這一點。也就是說,我希望用戶不斷克隆/推送/推送舊版本,同時將這些提交移植到新版本中。最終,「舊」服務器將被刪除,用戶將開始使用新的子模塊。我有一個jenkins服務器,負責將每個舊服務器的所有reposs每個晚上都移植到新服務器上。 再說一遍,除非我希望新回購有一些舊回購沒有的子模塊,否則這將是非常直接的。因此,情況會是這樣:

Old Repo  New Repo 
    |    | 
CommitA-------->CommitA 
    |    | 
    |   CommitB (Add submodules) 
    |    | 
CommitC-------->CommitC 
    |    | 
CommitD-------->CommitD 
    |    | 
    .    . 
    .    . 
    .    . 

因此,大家可以看到我想要的端口從老回購到一個新提交的所有失去whitout它們的任何信息(我不想只是從複製源舊的,並覆蓋它們在新的回購,因爲這將失去意見和中間承諾,因爲該移植操作將每天執行一次)。

有人可以給我一些關於如何實現這一點的提示,也可以如何在「自動」模式下執行它(不只是櫻桃一個接一個地提交)。

謝謝!

編輯

所以我一直在努力和現在我有:

#Clone "New Repo" 
git clone ssh://<NewRepoServer>/bitbucket_tests bitbucket_tests 
cd bitbucket_tests 
#Add "Old Repo" remote 
git remote add old_repo <OldRepoServer/bitbucket_tests>; 
#update New Repo remote 
git remote update origin; 
#update Old Repo remote 
git remote update old_repo; 
#Loop through all branches, and try to merge them 
for remote_branch in `git branch -r | grep old_repo | grep -v master | grep -v HEAD | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do 
    git branch -f --track $remote_branch 
    git checkout $remote_branch 
    git pull -s recursive -X patience -X theirs old_repo $remote_branch 
    git pull 
done 
git checkout master 
git pull -s recursive -X patience -X theirs old_repo master 
git pull 

#Push results to Old Repo 
git push origin refs/remotes/old_repo/*:refs/heads/*; 

雖然如果沒有修改,「新回購」分支這工作得很好,當NewRepo有失敗一些在OldRepo中不存在的提交(例如上圖中的CommitB):

git push origin 'refs/remotes/old_repo/*:refs/heads/*' 
To ssh://<NewRepoServer>/bitbucket_tests 
! [rejected]  old_repo/testBranch -> testBranch (non-fast-forward) 
error: failed to push some refs to     'ssh://<NewRepoServer>/bitbucket_tests' 
hint: Updates were rejected because a pushed branch tip is behind its remote 
hint: counterpart. Check out this branch and integrate the remote changes 
hint: (e.g. 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

我該如何自動更新將這些更改自動轉換爲OldRepo的內容,而無需用戶干預?

回答

0

我希望我理解你的權利。我想最簡單的方法來處理這個問題,就是將另一個/新的遠程分支/分支添加到您的新服務器,並取回&。所以你將擁有所有的提交和歷史。 欲瞭解更多信息,你可以閱讀https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches

如果我錯了,請糾正我。

+0

當從舊遙控器拉出所有分支並將其推向一個分支時,我遇到了問題。如果新的分支出現在舊的遙控器上怎麼辦?你會推薦什麼樣的命令序列? – viterbi

+0

1.使用'git fetch --all'和'git pull'從您的舊遠程分支獲取並提取所有更改到您的本地存儲庫 2.添加您的新遠程URL,並使用'git將您的本地分支推送到新遠程遠程添加newRemote URL「和'git remote -v',您可以檢查新的Remote的URL是否正確。然後將您的本地分支機構推送到您的新Remote中 –