gpt4 book ai didi

git - git filter-branch 的 --prune-empty 开关不会修剪分支开头的空提交

转载 作者:太空狗 更新时间:2023-10-29 14:44:22 25 4
gpt4 key购买 nike

我在主分支的开头有一个提交,其中包含一个 .gitignore 文件。

当我运行时

git filter-branch -f --tree-filter 'git rm .gitignore' --prune-empty

新树仍然包含该节点,尽管它是空的(.gitignore 文件已被删除),所以工作已经完成了一半。

为什么不 --prune-empty 修剪空提交?还是我误解了那个开关?

最佳答案

git filter-branchprune-empty 选项确实提到:

this switch only applies for commits that have one and only one parent

如果您修改的提交是“在 master 分支的开头”,它有 0 个父级。
那个特定的提交,即使是空的,也不会被修剪。


如果您修改的提交是“在分支的开头”,

beginning of a branch b
|
v
--x--Y--z--z
\
b--b

it should be pruned仅当该空提交与先前的提交相同时。

作为torek mentions here :*

an "empty commit" is really one that has the same tree as the previous commit: it's not that it has no files at all, it's that it has all the same files, with the same modes, and the same contents, as its parent commit.
This is because git stores complete snapshots for each commit, not differences from one commit to the next.

正如文档所说:

Some kind of filters will generate empty commits, that left the tree untouched.

因此从过滤器分支的角度来看,带有“0 个文件”的提交不是“空提交”,除非父提交有“0文件”(即相同的 empty "semi-secret" tree )

关于git - git filter-branch 的 --prune-empty 开关不会修剪分支开头的空提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36882818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com