Search code examples
gitgithubgit-mergemerge-conflict-resolutiongit-revert

Revert commit with Large file and resolve binary merge conflict


I want to push my commits to GitHub, but it doesn't allow me because the file Extras.pkl is too large. I have (accidentally) added that file 7 commits back in dfa4bfe, but is currently nowhere to find in my repository (it appears to be deleted). git revert dfa4bfe prompts

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

That is because there were 2 images in that same commit (one is creating the conflict).

I used git checkout --ours/theirs "MuonRate/nHits_distribution.png" to assign the version manually and used git add and git commit to commit these. But then I get the following:

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

Note the last 3th and last line. When I use git commit -m "empty commit to escape revert" --allow-empty, then the line You are currently reverting commit dfa4bfe. disappears. But then if I git push origin main, I get the exact same error saying that the file Extras.pkl is too large.

QUESTION: How can I undo the commit from Extras.pkl and resolve the binary issue?

Git log:

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

Note:, none of my commits during the reverting appears in the history. The problems lies in the commit dfa4bfe Add HRV split graph and z direction dist.


Solution

  • Following the github page regarding sensitive information, I have resolved the issue. For future reference and others:

    Skip the following 2 steps if the problem is within your local repo:

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

    Change PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA to your file location, but leave the quotation marks.

    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. Press enter twice
    3. git push ORIGIN MAIN