在filter-branch --tree-filter之后从git repo删除refs / original / heads / master? [英] Remove refs/original/heads/master from git repo after filter-branch --tree-filter?

查看:468
本文介绍了在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 *;请触摸$ dir / source-file- $ dir.py;完成
git init
git add。
git commit -m'初始提交'

现在我们有原始海报的问题了。让我们将git repo的根移到project-root,使用上面的链接:过滤器'mkdir -p path / to / module; git mv dir1 dir2 dir3 path / to / module'HEAD
rm -rf path
cd ../../../#现在PWD是项目根目录
mv path / to /模块/ .git。
git reset --hard

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

  gitk --all& 
git show-ref

如何摆脱 refs / original / heads / master 和所有关联的历史记录?

解决方案

refs / original / * 是否存在备份,以防你搞乱你的过滤分支。相信我,这真的是个好主意。



一旦你检查了结果,并且你非常有把握地确信你拥有了你想要,你可以删除备份的ref:

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

或者如果你对很多参考文献都这样做了,并且想要全部清除:

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

(这是直接从filter-branch手册页获取的。 )这不适用于你,但对于其他人可能会发现这一点:如果你做一个过滤器分支删除内容采取增加大量的磁盘空间,你可能还想运行 git reflog expire --expire = now --all git gc --prune = now 过期你的reflog并删除现在未使用的对象。 (警告:完全不可逆转,在做之前要非常确定。)


I had the same question as asked here: New git repository in root directory to subsume an exist 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

Now, gitk --all shows two histories: one culminating in the current master, and one named 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.

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 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/master and all associated history?

解决方案

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.)

这篇关于在filter-branch --tree-filter之后从git repo删除refs / original / heads / master?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆