在 filter-branch --tree-filter 之后从 git repo 中删除 refs/original/heads/master?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7654822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:59:53  来源:igfitidea点击:

Remove refs/original/heads/master from git repo after filter-branch --tree-filter?

gitgit-rewrite-historygit-plumbing

提问by goofeedude

I had the same question as asked here: New git repository in root directory to subsume an exist repository in a sub-directory

我在这里问了同样的问题:New git repository in root directory to subsume an existing repository in a sub-directory

I followed this answer here: New git repository in root directory to subsume an exist repository in a sub-directory

我在这里遵循了这个答案:New git repository in root directory to subsume an existing repository in a sub-directory

Now, gitk --allshows two histories: one culminating in the current master, and one named original/refs/heads/master.

现在,gitk --all显示了两种历史:一种以当前master为高潮,另一种名为original/refs/heads/master

I don't know what this second history is, or how to remove it from the repo. I don't need two histories in my repository.

我不知道这第二个历史是什么,也不知道如何从 repo 中删除它。我的存储库中不需要两个历史记录。

How do I get rid of it?

我该如何摆脱它?

To reproduce yourself:

要重现自己:

mkdir -p project-root/path/to/module
cd project-root/path/to/module
mkdir dir1 dir2 dir3 
for dir in * ; do touch $dir/source-file-$dir.py ; done
git init
git add .
git commit -m 'Initial commit'

Now we have the original poster's problem. Let's move the root of the git repo to project-root using the answer linked above:

现在我们有了原始海报的问题。让我们使用上面链接的答案将 git repo 的根目录移动到 project-root :

git filter-branch --tree-filter 'mkdir -p path/to/module ; git mv dir1 dir2 dir3 path/to/module' HEAD
rm -rf path
cd ../../../ # Now PWD is project-root
mv path/to/module/.git .
git reset --hard

Now, see my current problem:

现在,看看我目前的问题:

gitk --all &
git show-ref

How do I get rid of refs/original/heads/masterand all associated history?

我如何摆脱refs/original/heads/master和所有相关的历史?

回答by Cascabel

refs/original/*is there as a backup, in case you mess up your filter-branch. Believe me, it's a reallygood idea.

refs/original/*是否有备份,以防您弄乱过滤器分支。相信我,这真是个好主意。

Once you've inspected the results, and you're very confident that you have what you want, you can remove the backed up ref:

一旦您检查了结果,并且您非常有信心拥有您想要的东西,您就可以删除备份的 ref:

git update-ref -d refs/original/refs/heads/master

or if you did this to many refs, and you want to wipe it all out:

或者,如果您对许多裁判这样做了,并且想将其全部清除:

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d

(That's taken directly from the filter-branch manpage.)

(这直接取自过滤器分支联机帮助页。)

This doesn't apply to you, but to others who may find this: If you do a filter-branch which removescontent taking up significant disk space, you might also want to run git reflog expire --expire=now --alland git gc --prune=nowto expire your reflogs and delete the now-unused objects. (Warning: completely, totally irreversible. Be very sure before you do it.)

这不适用于您,但适用于可能会发现此问题的其他人:如果您执行过滤器分支删除占用大量磁盘空间的内容,您可能还希望运行git reflog expire --expire=now --all并使git gc --prune=now您的引用日志过期并删除现在未使用的对象. (警告:完全,完全不可逆。在你做之前要非常确定。)

回答by Guilherme Duarte

And if you're in Windows PowerShell:

如果您使用的是 Windows PowerShell:

git for-each-ref --format="%(refname)" refs/original/ | foreach-object -process { git update-ref -d $_ }

回答by Kiryl Plyashkevich

filter-branchkeeps backups so repository need to clean up reflogs and garbage collect. Make sure that have no need in this backups before deletion:

filter-branch保留备份,因此存储库需要清理引用日志和垃圾收集。确保在删除之前不需要此备份:

rm -Rf .git/refs/original
git gc --aggressive --prune=now