git不再能够重写历史记录 [英] git no longer able to rewrite history

查看:71
本文介绍了git不再能够重写历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用以下命令:

I have been using commands like:

git filter-branch --index-filter \
           'git ls-files -s | sed "s_subdir/__" |
                   GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                           git update-index --index-info &&
            mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

将目录树从子目录"subdir"移到顶层.为了在不同且成功的过滤树后清理回购协议,我尝试使用:

to move a directory tree from a subdirectory "subdir" to the top-level. In order to clean up the repo after a different and also successful filter-tree, I've tried using:

git filter-branch --tag-name-filter cat -- --all
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' HEAD
git reflog expire --all --expire=now
git gc --prune=now --aggressive      

这包含了一些有关行车路线的建议.但是,执行此筛选器分支后将不再起作用:

This mixes a couple of recommendations from hereabouts. However, after doing this filter-branch no longer works:

Rewrite 07436df7a2795910fb0b718d1a1b84e195cfabea (1/113) (0 seconds passed, remaining 0 predicted)    mv: cannot stat ‘somepathhere/.git-rewrite/t/../index.new’: No such file or directory
index filter failed: git ls-files -s | sed "_subdir/__" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
 mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"

我不清楚为什么应该这样,或者我使用了哪个"voodoo"清理命令负责.显然,我的 git-fu 中缺少一些知识.有人可以建议那是什么吗?

I'm am not at all clear why this should be or which of the 'voodoo' clean up commands I used was responsible. Obviously some knowledge is missing from my git-fu. Can someone suggest what that could be?

推荐答案

重写失败,因为在"subdir"不存在的情况下至少存在一次提交.对我有用的解决方法是通过添加";/bin/true "

The rewrite was failing because there was at least one commit where 'subdir' didn't exist. The fix that works for me is to alter the filter to ignore erorrs by adding "; /bin/true"

git filter-branch --index-filter \
           'git ls-files -s | sed "s_subdir/__" |
                   GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                           git update-index --index-info &&
            mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"; /bin/true' HEAD

这似乎等同于-index-filter -ignore-unmatch .

我仍然不确定为什么以前的空提交未被删除:

I am still unsure why the empty commits were not removed by the previous:

git filter-branch --prune-empty --tag-name-filter cat -- --all
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"' HEAD

但是有一个解决方案(来自这个问题):

However there is a solution to that (from this question):

git filter-branch --parent-filter "sed 's/-p <the_commit>//'" HEAD

这会剪掉最初的提交,只是没有文件的注释(由于先前的重写).完成此操作后,可能不再需要;/bin/true"技巧.

This snips off the initial commit which is just a comment with no files (as a result of earlier rewriting). Once this is done the ";/bin/true" trick may no longer be required.

这篇关于git不再能够重写历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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