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

我在这里问了同样的问题:在根目录中新建Git存储库,将现有存储库包含在子目录中

我在这里遵循这个答案:在根目录中新建Git存储库,将现有存储库包含在子目录中

现在,gitk --all显示了两个历史:一个在当前master中达到顶点,另一个命名为original/refs/heads/master

我不知道这第二段历史是什么,也不知道如何将其从回购协议中删除。我的存储库中不需要两个历史记录。

我怎么才能摆脱它?

要复制自己:

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'

现在我们有了原发帖人的问题。让我们使用上面链接的答案将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

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

gitk --all &
git show-ref

如何删除refs/original/heads/master和所有相关历史记录?

48139 次浏览

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

Once you've inspected the results, and you're very confident that you have what you want, you can remove the backed up 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 removes content taking up significant disk space, you might also want to run git reflog expire --expire=now --all and git gc --prune=now to expire your reflogs and delete the now-unused objects. (Warning: completely, totally irreversible. Be very sure before you do it.)

And if you're in Windows PowerShell:

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

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

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