[英]Removing Git commits on a branch
How do I remove commits that are branched off master
? 如何删除分支
master
提交?
I have added a large library, along with a very rich commit history (and that predates my code) to a subdirectory via Git subtree . 我已经通过Git子树添加了一个大型库,以及一个非常丰富的提交历史(并且在我的代码之前)到一个子目录。 I'd like to retroactively squash that entire history, but still be able to merge in new commits to the library .
我想追溯整个历史, 但仍然可以合并到新的提交到库 。
I have tried various combinations of git rebase
but I never get the expected result [*]. 我尝试了各种
git rebase
组合,但我从未得到预期的结果[*]。
My repository looks something like: 我的存储库看起来像:
A---B-----------F---G master
/
... C---D---E
and I'd like for it to look something like: 我希望它看起来像:
A---B-----------F'--G' master
/
E'
or: 要么:
A---B-------E'--F'--G' master
[*]: [*]:
git rebase --onto CE master
git checkout F; git rebase --onto CE master
This is history editing. 这是历史编辑。 You will end up in something like
你最终会得到类似的东西
A---B-----------F'---G' master / E'
Merging will be a problem after this, because of Git will not be able to find common parents between your history and libraries's history. 在此之后合并将是一个问题,因为Git将无法在您的历史和图书馆历史之间找到共同的父母。
To actually do it you need to 要真正做到这一点你需要
--no-commit
. --no-commit
执行合并。 The history will look like 历史将是如此
A---B-----------F'---G'
To make the shallow clone of the library, you need to do something like this (Warning: untested): 要制作库的浅层克隆,您需要执行以下操作(警告:未经测试):
git format-patch F --stdout > ~/saved_commits.patch
) git format-patch F --stdout > ~/saved_commits.patch
)的git format-patch F --stdout > ~/saved_commits.patch
git remote rm
git remote rm
git reflog expire --expire=now --all
git reflog expire --expire=now --all
git gc --prune=now
. git gc --prune=now
。 Now you should see the repository shrank. git fetch --depth=10 libraryremote
git am ~/saved_commits.patch
). git am ~/saved_commits.patch
)。 To migrate into submodules solution (the best option probably), you need to rollback to the state before merge and set up submodules, then substitute each merge with changed commit-id for submodule. 要迁移到子模块解决方案(可能是最好的选项),您需要回滚到合并之前的状态并设置子模块,然后用更改的commit-id替换每个合并用于子模块。 Unlike for the case of splitting out project directory to submodule I don't know the automated solution for this (but it can be implemented the similar way).
与将项目目录拆分为子模块的情况不同,我不知道这个的自动化解决方案(但它可以以类似的方式实现)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.