0

I git committed a large tar file (tens of GB). Oops. I then made a few more commits. I then tried to push to an existing remote repository on github of the simplest form (a single branch and I am the only user). Upon pushing I received the error:

Username for 'https://github.com': username
Enumerating objects: 77, done.
Counting objects: 100% (77/77), done.
Delta compression using up to 56 threads
Compressing objects: 100% (57/57), done.
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
Writing objects: 100% (58/58), 16.90 GiB | 75.81 MiB/s, done.
Total 58 (delta 25), reused 1 (delta 0), pack-reused 0
fatal: the remote end hung up unexpectedly
Everything up-to-date

But the repo is not up to date. I tried increasing the buffer following this question but the issue was not resolved. I probably shouldn't be trying to push a tens of GBs tar file and I should back it up elsewhere. I've since removed the large tar file from my local repo.

So I'd like to remove the commit where I committed a ridiculously large tar file but keep the other commits, and push again. I've scanned similar questions but I am overwhelmed by suggestions of reset vs rebase vs a plethora of other suggestions that I'm not adept enough with git to understand. How do I remove a commit from 5 commits ago, where I committed a ridiculously large tar file, while keeping the other commits to push?

$ git log
commit 157b030df1da4a02d0a9b4424e70dc1c4cf18eba (HEAD -> master)
Author: username 
Date:   Tue Nov 24 13:55:00 2020 -0600
    Removed a directory

commit ba07a1e99d5702361e9b0a8c7441723e6ac82faf
Author: username
Date:   Tue Nov 24 13:50:37 2020 -0600
    Moved a directory

commit ccb3de003b05e83444416655eddbe83e3ff5b042
Author: username 
Date:   Tue Nov 24 11:19:53 2020 -0600
    Modified a file

commit 1eff1c6f31f04bd02a536f3ef0ee9ff5e1681904
Author: username 
Date:   Tue Nov 24 11:18:25 2020 -0600
    Modified a file

commit 69ee1de9a3e7fce35548e5d32cd168c32f0de945
Author: username 
Date:   Tue Nov 24 11:16:36 2020 -0600
    Added a ridiculously large tar file


commit 8b70afae41f05c6108688c8ef1f987628d9fad82
Author: username
Date:   Tue Nov 24 09:37:01 2020 -0600
    Added a bunch of files
astromonerd
  • 907
  • 1
  • 15
  • 32
  • *I've since removed the large tar file from my local repo.* This is, as you've discovered, the wrong way to phrase it: it's still in the *repository*. It's just not in some of the *commits*. :-) This is a really common problem, though. – torek Dec 19 '20 at 12:52
  • For your particular case, as long as commit `69ee1de9a3e7fce35548e5d32cd168c32f0de945`'s effect is *only* to add the big tar file, I'd go with [the answer GreenGiant posted](https://stackoverflow.com/a/65362720/1256452). – torek Dec 19 '20 at 12:58

1 Answers1

4

I recommend using the interactive rebase tool.

Take a look at https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History (go to "Changing Multiple Commit Messages")

The commit you want to skip is 69ee1de9, which is 5 commits deep into the history, so use HEAD~5 below.

$ git rebase -i HEAD~5

This will give you a list of commits in your editor.

Change the line that has 69ee1de9 to have the verb "drop" instead of "pick". That line will look something like:

drop 69ee1de9 Added a ridiculously large tar file

Then save and exit your editor and git will do the rest.

GreenGiant
  • 4,930
  • 1
  • 46
  • 76