1

I accidentally committed a zip of the whole solution 4 commits ago. I realized this after I tried to push and git bash showed I was uploading something larger than 100mb.

So far I've tried to:

  • Delete the file locally and commit that change (this still leaves the huge packfile which still seems to be causing a problem when pushing)
  • Used git revert -n c5d1516c (which is the specific commit that includes the zip. I figured I would then add .zip to the gitignore then commit that and hope the 600mb pack file would resolve itself but this is not working either)

I've tried a few other approaches but I'm not the best at git so I'm at a loss of direction

Here is my commit history. The highlighted one is the one that contains the zip file that I need to remove and also remove from git history.
enter image description here

How can I undo the highlighted commit so that I can ignore the zip file and fix my pack file issue?

Adrian
  • 3,332
  • 5
  • 34
  • 52
  • Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – phd Jun 03 '18 at 19:17

2 Answers2

3

The following can be done safely only if you haven't pushed yet.

You could do rebase -i and remove the commit. Personally I don't like rebasing because there are a lot of actions happening under the hood. And you may want to remove only 1 file from the bad commit.

So if you're okay with squashing your local changes into 1 commit, then it's easier:

  1. git reset --soft [commit hash before zip]
  2. remove zip file
  3. Commit all your local changes
Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45
0

You have accepted an answer already but it looks like you have basically "lost" the 4 revisions that you had made and you got a single revision saying "This is the work of 4 other revisions that I busted for not being careful". A much better solution that would keep your whole history as it was while removing the zip would be (assumming we are working on master):

git checkout master~4 # go back to where the zip was added
git rm --cached the-zip-file.zip # remove the zip file from revision
git commit --amend --no-edit # commit without zip file, leaving everything else as is
git cherry-pick master~4..master # replicate revisions created on top of busted revision
git branch -f master # move master to new revision
git checkout master

At this point you kept your history while removing the zip file.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • 1
    Which is basically the manual way of doing `git rebase -i` like th accepted answer already mentions, isn't it? – AmShaegar Jun 03 '18 at 00:36
  • Oh! Totally missed it. Just looked at the recipe and didn't read what had been written before. Not that **git rebase -i** is _totally_ automatic, but anyway. It's fine. – eftshift0 Jun 03 '18 at 00:49