我想根据git文档从git历史记录中删除一些文件/文件夹,但是由于unstaged changes
而失败。对于我来说,还不清楚会发生什么非阶段性的变化,就像我以前做的git add --all
、commit和push一样。注意,要删除的文件夹somefolder/
不再存在于HEAD中.它是在以前提交的,但是它的旧版本需要从回购中清除。
~$ git add --all
~$ git commit -m "trying to fix 'Cannot rewrite branches: You have unstaged changes'"
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~$ git push
Everything up-to-date
~$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
~$ git filter-branch --force --index-filter "git rm --cached --ignore-unmatch somefolder/" --prune-empty --tag-name-filter cat -- --all
Cannot rewrite branches: You have unstaged changes.
~$
如何解决这个问题,以便成功地运行最后一个命令?
发布于 2020-04-04 20:15:03
首先,确保使用最新的Git (2.26),作为关于在较早的Git版本中有一个bug。的git滤波器-分支。
其次,您可能需要将您的repo克隆为一个裸存储库,并在那里进行筛选。。这将防止任何未分阶段的更改,因为裸存储库没有工作树。
但是,不要为此使用git filter-branch
。
使用新工具git filter-repo
(直接在您的常规本地存储库中,尽管备份在这种筛选之前总是一个好主意)
使用路径滤波
git filter-repo --path somefolder/ --invert-paths
这将从Git存储库历史记录中删除somefolder/
。
https://stackoverflow.com/questions/61025680
复制相似问题