如何删除过滤分支后的旧提交? [英] how to remove old commits after filter-branch?
问题描述
我使用了filter-branch来修复一个不正确的电子邮件地址在我的存储库,但所有的分支机构现在MIA(除主)。
这就是 filter-branch $ c $之前显示的
git graph
c>:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ | * 08e7463(f1)加b
| /
* 7c7bd91加
我发布了这个filter-branch命令:
git filter-branch --env-filter'export GIT_AUTHOR_EMAIL =fixed-email ;
GIT_AUTHOR_NAME =fixed-author'
得到这个:
* 770262a(HEAD,master)合并分支'f1'
| \
| * 0f58ab5添加b
| /
* fb012a9添加
* d93c7ee(refs / original / refs / heads / master)合并分支'f1'
| \
| * 08e7463(f1)加b
| /
* 7c7bd91加
一些让我烦恼的事情:
<1> f1
分支未被移动到0f58ab5。
2)在fb012a9之前的所有提交看起来都与我无关,我可以摆脱它们吗?
我在另一个问题中看到有人建议:
rm -rf .git / refs / original /
git reflog expire --expire = now --all
git gc --aggressive --prune = now
但这并没有太大的帮助,这是我得到的之后:
$ $ p $ $ $ c $ 770262a(HEAD,master)合并分支'f1'
| \
| * 0f58ab5添加b
| /
* fb012a9添加
* 08e7463(f1)添加b
* 7c7bd91添加
编辑:做什么VonC建议产生这张图:
* 211632d(HEAD,master)合并分支'f1'
| \
| * bda7577(f1)添加b
| /
* 70c7b34添加
* 3182b33(refs / original / refs / heads / master)合并分支'f1'
| \
| * 8b81c21(refs / original / refs / heads / f1)加上b
| /
* 4c07dc9加上
解决了问题#1,现在我只需要找到一种方法来摆脱旧的提交,我该如何实现它?
你可以在最后使用' - --all
'再次尝试你的git filter-branch, p>
git filter-branch --env-filter'export GIT_AUTHOR_EMAIL =fixed-email;
GIT_AUTHOR_NAME =fixed-author' - --all
注意: p>
- 将过滤分支选项与修订选项分开的
-
> - 和
- 全部
改为重写所有分支和标签。
也就是说,在你目前的情况下,没有任何数量的 git gc ... prune ...
仍然被分支标记引用,如 f1
,它仍然指向 08e7463
。
So你看到的是正常的,通过设计。
OP报告说,一旦完成 git filter-branch ... - --all
,a rm -r .git / refs / original
负责旧提交。
同样,这也不足为奇:没有标签或分支引用它们,这次意味着它们可以永久从Git仓库中删除。 b $ b
I used filter-branch to fix an incorrect email address in my repository but all the branches are now MIA (except master).
This is what git graph
showed prior to filter-branch
:
* d93c7ee (HEAD, master) Merge branch 'f1'
|\
| * 08e7463 (f1) adding b
|/
* 7c7bd91 adding a
I issued this filter-branch command:
git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL="fixed-email";
GIT_AUTHOR_NAME="fixed-author"'
And got this:
* 770262a (HEAD, master) Merge branch 'f1'
|\
| * 0f58ab5 adding b
|/
* fb012a9 adding a
* d93c7ee (refs/original/refs/heads/master) Merge branch 'f1'
|\
| * 08e7463 (f1) adding b
|/
* 7c7bd91 adding a
A few things that bother me:
1) f1
branch wasn't moved to 0f58ab5.
2) All commits before fb012a9 seem irrelevant to me, can I get rid of them?
I saw in another question someone suggesting to:
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now
But it didn't quite help, this is what I got afterwards:
* 770262a (HEAD, master) Merge branch 'f1'
|\
| * 0f58ab5 adding b
|/
* fb012a9 adding a
* 08e7463 (f1) adding b
* 7c7bd91 adding a
EDIT: doing what VonC had suggested yielded this graph:
* 211632d (HEAD, master) Merge branch 'f1'
|\
| * bda7577 (f1) adding b
|/
* 70c7b34 adding a
* 3182b33 (refs/original/refs/heads/master) Merge branch 'f1'
|\
| * 8b81c21 (refs/original/refs/heads/f1) adding b
|/
* 4c07dc9 adding a
Which solved problem #1, now I only need to find a way to get rid of the old commits, how do I accomplish that?
Could you try again your git filter-branch with a '-- --all
' at the end, like:
git filter-branch --env-filter 'export GIT_AUTHOR_EMAIL="fixed-email";
GIT_AUTHOR_NAME="fixed-author"' -- --all
Note:
- the
--
that separates filter-branch options from revision options, - and the
--all
to rewrite all branches and tags.
That said, in your current situation, no amount of git gc ... prune ...
will remove a commit which is still referenced by a branch marker, like f1
which still points to 08e7463
.
So what you are seeing is normal, by design.
The OP reports that, once doing the git filter-branch ... -- --all
, a rm -r .git/refs/original
takes care of the old commits.
Again, this is not surprising: no tag or branch references them anymore, meaning this time, they are candidates for permanent removal from the Git repo.
这篇关于如何删除过滤分支后的旧提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!