tar*_*ius 10 git git-filter-branch
我想将使用更大应用程序分发的模块拆分为单独的子模块,并保持从上游拉出的能力.
所以这比Detach子目录更复杂到单独的Git存储库.我不仅一次使用git-filter-branch,而且希望在我完成之后保持上拉变量的能力(而上游没有).
只需在我的重写历史未发现上游现在包括新提交完整的历史重新运行git的过滤分支是不是一种选择,因为有数百个模块为此我不得不这样做,提交的数目越来越接近100.000 .
我猜这涉及将历史限制为新的提交,重写那些然后在之前重写的提交之后添加它们,但我不确定如何做到这一点 - 也许有更好的方法.
如果分支和标签也可以被保留,那将是很好的,但这不是绝对必要的,如果它使事情变得复杂,我实际上宁愿失去那些.
对于第一个rebase这样做:
git checkout -b rebased master
git filter-branch --some-filter
git tag rebased-done master
Run Code Online (Sandbox Code Playgroud)
并且"合并"以后的提交:
# 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1628 次 |
| 最近记录: |