簡體   English   中英

反復使用git-filter-branch重寫新的提交

[英]Repeatedly using git-filter-branch to rewrite new commits

我想將隨較大應用程序一起分發的模塊拆分為單獨的子模塊,並保持從上游拉出的能力。

因此,這比將子目錄分離到單獨的Git存儲庫中更為復雜。 我不僅要使用git-filter-branch一次,而且還希望在執行此操作后保持拉取上游更改的能力(而上游則沒有)。

現在,僅從上游重新在完整歷史記錄上重新運行git-filter-branch,包括在我的重寫歷史記錄中找不到的新提交是不可行的,因為我必須為此執行數百個模塊,並且提交數量接近100.000 。

我猜想這涉及將歷史記錄限制為僅新提交,然后重寫它們,然后在先前重寫的提交之后添加它們,但是我不確定如何執行此操作-也許有更好的方法。

如果分支和標簽也可以保留,那將是很好的選擇,但這不是絕對必要的,而且如果它使事情變得復雜,我實際上更希望丟失那些分支和標簽。

對於第一個基准,請執行以下操作:

git checkout -b rebased master
git filter-branch --some-filter
git tag rebased-done master

並“合並”以后提交:

# Create a tempory branch and rebase it's tail use 'rebase-done~'
# and not 'rebase-done' because some filters (like --index-filter)
# require this, others might not.
git checkout -b rebased-tail master
git filter-branch -f --some-filter -- rebased-done~..HEAD

# Get the commit in branch 'rebased' corresponding to tag 'rebase-done'
# (which tags a commit in 'master' not 'rebased').  Depending on your
# situation you might have to determine this commit differently (in my
# use case I am absolutely sure that there is never a commit with the
# same author date - if that doesn't work you might want to compare
# commit messages).
start_time=$(git show --quiet --pretty=%at rebased-done)
start_hash=$(
git log --reverse --pretty="%H %at" rebased_tail |
while read hash time
do
    [ "$time" = "$start_time" ] && echo $hash && break
done
)

# Finally apply the rebased commits.
git checkout rebased
git format-patch -k --stdout $start_hash..rebased-tail | git am -k
git branch -D rebased-tail
git tag -f rebased-done master

暫無
暫無

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

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