Reputation: 7333
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!
Upvotes: 1
Views: 1737
Reputation: 165546
In your first commit, you added a commit with data/
to your repository. By doing a git rm -r data/
and then git commit
you made a second commit which removes data/
. git push
has to upload both commits, so it hasn't helped matters.
In addition, git rm --cached
only removes data from the index. I don't think your second commit actually removed any files, but you can check that with git 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 master
is with git tag before_rebase
. Then if things go horribly wrong you can always go back to before_rebase
and try again.
You tell git you want to rewrite history going back to origin/master
with git rebase -i origin/master
. Then you'll get an editor with something like this:
pick 064f41f Some change
pick 1ca69c3 Some other change
pick 1fa8921 Remove data/
pick 984alkj Huge amounts of data/
pick 82adlkj Bug fix
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 log
to check that the changes are in fact gone.
Now you should be able to push and data/
is totally gone from history.
Upvotes: 2
Reputation: 81813
As far as I can tell from your question, you removed the data from the repository, and then committed the deletion. So the data is still there in a previous commit.
To get rid of the data, you may be able to use an interactive rebase (git rebase -i
). For example, suppose your history looks like this:
Then you may run git rebase -i HEAD~5
(the 5 is how many commits you want to rebase interactively). This will open an editor. In this editor, delete the commit in which you added the large data files, and delete the commit in which you deleted the large data files. Save the file and exit the editor. Git will then rebuild your branch without those two commits in it, so it will look like this:
After that, git push should not send the data anymore.
Upvotes: 1
Reputation:
If the offending data subdirectory is still in the folder you're trying to commit, git will attempt to commit it regardless of whether or not you removed it. It will just see it as a new file instead.
To fix this error, you can either remove the directory from the commit entirely, or configure a .gitignore
(see here for general instructions about .gitignore syntax).
Upvotes: 0