使用大文件还原提交并解决二进制合并冲突

问题描述

我想 push 我对 GitHub 的提交,但它不允许我,因为文件 Extras.pkl 太大。我(不小心)添加文件 7 提交回 dfa4bfe,但目前在我的存储库中找不到(它似乎已被删除)。 git revert dfa4bfe 提示

warning: Cannot merge binary files: MuonRate/nHits_distribution.png (HEAD vs. parent of dfa4bfe... Add HRV split graph and z direction dist) 
error: Could not revert dfa4bfe... Add HRV split graph and z direction dist

那是因为在同一个提交中有 2 个图像(一个导致冲突)。

我使用 git checkout --ours/theirs "MuonRate/nHits_distribution.png" 手动分配版本并使用 git addgit commit 提交这些。但后来我得到以下信息:

Your branch is ahead of 'origin/main' by 9 commits.
  (use "git push" to publish your local commits)
You are currently reverting commit dfa4bfe.

Untracked files:
        #some unimportant files

nothing added to commit but untracked files present

注意最后第三行和最后一行。当我使用 git commit -m "empty commit to escape revert" --allow-empty 时,You are currently reverting commit dfa4bfe. 行就会消失。但是如果我 git push origin main,我会得到完全相同的错误,指出文件 Extras.pkl 太大。

问题:如何从 Extras.pkl 撤消提交并解决二进制问题?

Git 日志:

* da43e5a (HEAD -> main) empty commit to escape revert
* e8d3f7a add .gitignore
* 633b6f2 Delete extrapkl
* 9f2366b .
* e2c9712 Add mplstyle
* b3702dc Rerun and delete filters for V9
* dfa4bfe Add HRV split graph and z direction dist
* 76bee13 Plot nHist complete
* 7f227ea First histogram of nHits
* b82b78b Create Multi directory data loop
etc.

注意:,我在恢复期间的所有提交都没有出现在历史记录中。 问题在于提交 dfa4bfe Add HRV split graph and z direction dist

解决方法

the github page regarding sensitive information 之后,我解决了这个问题。以供将来参考和其他:

如果问题出在您的本地存储库中,请跳过以下 2 个步骤:

  1. git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
  2. cd YOUR-REPOSITORY

PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA 更改为您的文件位置,但保留引号。

  1. git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \ --prune-empty --tag-name-filter cat -- --all
  2. 按两次回车
  3. git push ORIGIN MAIN