我不小心推送了一些大文件的提交,然后又恢复了它。但这会导致任何 pull 此分支的人都在历史记录中获取这些文件,因此我决定删除或压缩这两个提交。然而,一些分支已经 merge 进来。我不知道如何让“git rebase -i”保持分支结构。
历史现在看起来是这样的:
H - new commits
|
G - merge
| \
| F - commits on another branch
| |
E | - some other commits
| |
D | - corrected B
| |
C | - revert B
| |
B | - huge files
| /
A - early commit
可以改成关注吗?
h - new commits
|
g - merge
| \
| F - commits on another branch
| |
e | - some other commits
| |
d | - corrected B
| /
A - early commit
最佳答案
是的你可以但你不应该。
它会要求你重写历史并替换服务器上已经推送的历史(这需要强制推送并且通常会导致每个人都对你大喊大叫)。
但是如果你真的想要那么 git filter-branch
就是你想要使用的,就像在 this SO answer 中一样.所以你会做这样的事情:
git filter-branch --commit-filter '
if [ "$GIT_COMMIT" = "<your commit to remove here>" ]
then
skip_commit "$@";
else
git commit-tree "$@";
fi' HEAD
还有几个例子here .
关于git - 从 merge 分支中删除提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39530965/