![](/img/trans.png)
[英]Updating git repo after using git-filter-repo --subdirectory-filter
[英]How to use git-filter-repo to merge one repo as subdirectory into another
在嘗試使用git filter-branch
使用此gist合並存儲庫時。 僅添加有問題的相關代碼段:
git filter-branch -f --prune-empty --tree-filter '
mkdir -p "${REPO_NAME}_tmp"
git ls-tree --name-only $GIT_COMMIT | xargs -I{} mv {} "${REPO_NAME}_tmp"
mv "${REPO_NAME}_tmp" "$REPO_NAME"
'
我收到來自 git 的警告,說明如下:
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
所以,我看了一下git filter-repo
, 描述如下:
重組文件布局(例如將所有文件移動到子目錄中以准備與另一個 repo 合並,...
這表明這個問題可以通過git filter-repo
解決,但即使在檢查了文檔和給出的示例之后,我也找不到實現此目的的方法。 有人可以幫助我嗎?
替換腳本中的filter-branch
命令
git filter-branch -f --prune-empty --tree-filter '
mkdir -p "${REPO_NAME}_tmp"
git ls-tree --name-only $GIT_COMMIT | xargs -I{} mv {} "${REPO_NAME}_tmp"
mv "${REPO_NAME}_tmp" "$REPO_NAME"
'
有了這個
git filter-repo --to-subdirectory-filter "$REPO_NAME"
請參閱此處的路徑快捷方式部分
--to-subdirectory-filter
<directory>
將項目根目錄視為位於
<directory>
下等效於使用
--path-rename:<directory>/
這看起來像一個路徑重命名,作為基於路徑的過濾器的一部分:
cd $REPO_DIR_TMP
git filter-repo --path-rename /:${REPO_NAME}_tmp/
這將重寫子文件夾中第二個 repo 的歷史記錄(在第二個 repo 內)
然后你可以將它添加為第一個 repo 的遠程,獲取和合並,就像在你的 gitst 中一樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.