首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反复使用git-filter-branch重写新的提交

反复使用git-filter-branch重写新的提交
EN

Stack Overflow用户
提问于 2010-02-19 19:55:31
回答 1查看 2K关注 0票数 10

我想将与更大的应用程序一起分发的模块拆分成单独的子模块,并保持从上游拉取的能力。

所以这比Detach subdirectory into separate Git repository更复杂。我不仅需要使用一次git-filter-branch,还希望在这样做之后(而上游还没有)保留拉取上游更改的能力。

简单地在上游的完整历史上重新运行git-filter-branch,包括在我重写的历史中找不到的新提交,是不可行的,因为有成百上千的模块我必须这样做,提交的数量接近100.000。

我猜这包括将历史记录限制到新的提交,重写这些提交,然后在之前重写的提交之后添加它们,但我不确定如何做到这一点-也许有更好的方法。

如果分支和标记也能保留下来就好了,但这并不是绝对必要的,如果它使事情变得复杂,我实际上更愿意去掉它们。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-27 02:28:51

对于第一个rebase,执行以下操作:

代码语言:javascript
复制
git checkout -b rebased master
git filter-branch --some-filter
git tag rebased-done master

然后“合并”提交:

代码语言:javascript
复制
# 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
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2296047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档