本文介绍了Git filter-branch给了我两套提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从提交历史记录中删除文件.我遵循了 Github删除敏感数据的说明:

I needed to remove a file from my commit history. I followed Github's instructions for removing sensitive data:

$ git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch <myfile>' \
--prune-empty --tag-name-filter cat -- --all

...但是我一定做错了,因为现在我有一堆重复的提交.一组提交仍然有我的文件;另一个没有.除此之外,它们是相同的.如何删除仍包含文件的所有提交?

...but I must have done something wrong, because now I have a bunch of duplicate commits. One set of commits still has my file; the other doesn't. Other than that, they're identical. How can I delete all of the commits that still contain my file?

推荐答案

考虑到问题,现有答案及其评论中的信息,看来原始发帖人在执行git filter-branch后犯了一些错误,并且没有为该存储库做备份克隆.

Given the information from the question, the existing answers, and their comments, it appears that the original poster made a few mistakes after doing the git filter-branch, and didn't make a backup clone of the repo.

因此,如果原始发帖人想要这样做,那么这里是有关将回购返回到过滤器分支之前的先前状态的说明.

git filter-branch 将自动保存对旧提交的引用,以防万一您出于任何原因需要对其进行恢复.您将在存储库的.git/refs/original/refs/目录下找到它们:

ls -l .git/refs/original/refs/heads/
total 1
-rw-r--r--    1 Keoki    Administ       41 May 23 01:13 master

ls -l .git/refs/original/refs/tags/
total 1
-rw-r--r--    1 Keoki    Administ       41 May 23 01:13 v1.0

以上每个参考都包含旧提交的提交sha ID:

Each of the above references contains the commit sha ID of your old commits:

cat .git/refs/original/refs/heads/master
276fc24dc4b12edf75aea40f4fd50e25a5840005

cat .git/refs/original/refs/tags/v1.0
475593a612141506f59a141e38b8c6a3a2917f85

使用硬重置进行恢复

要恢复原始的master分支(从执行过滤器分支之前开始),只需使用上面的引用进行硬重置,或使用其中包含的提交sha ID:

Use hard resets to recover

To get back your original master branch (from before you did the filter-branch), just do a hard reset using the references above, or use the commit sha ID contained in them:

git checkout master

# Use reference
git reset --hard refs/original/refs/heads/master

# Or use sha ID
git reset --hard 276fc24dc4b12edf75aea40f4fd50e25a5840005

这篇关于Git filter-branch给了我两套提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 13:24
查看更多