I accidentally ran commit on a git project with lots of data files in it– these are several GB in size.
Then I tried to run push origin master. It compressed everything (over several minutes) and then tried to upload it to the server. I tried several times, but no luck. It is a free git server, and so the push was unsuccessful (probably the project size). The error was:
Compressing objects: 100% (101/101), done. error: RPC failed;
result=55, HTTP code = 0 fatal: The remote end hung up unexpectedly
Writing objects: 100% (101/101), 5.55 GiB | 10.39 MiB/s, done. Total
101 (delta 21), reused 0 (delta 0) fatal: The remote end hung up
unexpectedly fatal: expected ok/error, helper said
‘0009[ffefJMeysq/IJJ,Rj:V{L<wܜ[G>@}"<}5{>zQw\~Q’
Now I’ve removed the offending data subdirectory using git rm --cached -r data/ and (just to be safe) moved it to another directory. I reran git commit and then tried to do a git push— but it’s still trying to move all of that data!
I would roll my entire project back to an earlier version, but unfortunately, I’ve been editing other files during this time.
Do you know of a way that I can tell git to please forget the data directory existed? Thank you very much!
In your first commit, you added a commit with
data/to your repository. By doing agit rm -r data/and thengit commityou made a second commit which removesdata/.git pushhas to upload both commits, so it hasn’t helped matters.In addition,
git rm --cachedonly removes data from the index. I don’t think your second commit actually removed any files, but you can check that withgit log --stat.You need to rewrite your history with an interactive rebase. This is not so much rewriting history as rewriting new history. As an insurance policy, start by placing a tag where
masteris withgit tag before_rebase. Then if things go horribly wrong you can always go back tobefore_rebaseand try again.You tell git you want to rewrite history going back to
origin/masterwithgit rebase -i origin/master. Then you’ll get an editor with something like this:Simply delete the lines representing the offending commits, save and quit the editor. Git will then reapply each remaining change on top of each other. You may get conflicts, resolve them like any other merge.
Once you’re done, use
git logto check that the changes are in fact gone.Now you should be able to push and
data/is totally gone from history.