0

I committed and tried pushing a directory filled with large files.

git add . git commit -m "commit message" git push origin main

I got an error that the files were too large.

I then added the directory name to my .gitignore file and tried to push again.

models/ (this is a line I added to my .gitignore file)

I got the same error.

I deleted the files in that repo both locally and remotely.

I committed and tried pushing again but I got the same error.

I've been trying everything I can think of that won't mess up something I cannot undo, but have had no luck.

A question similar to mine is here.

How can I clear out those commits with the large files so I can start pushing again without losing remote AND local work?

4
  • 2
    Git doesn't push files. Git pushes commits (whole commits at a time). Commits do contain files, so in that sense, a git push sends files, but it didn't push them individually. It pushed a commit. If the commit contains files that the other machine hates and refuses to take, you'll have to make different commits. Commented Nov 10, 2020 at 0:58
  • @torek right, every commit I do has the same problem. Commented Nov 10, 2020 at 1:54
  • 2
    None of the actions you describe after making the first “big” commit has any effect on that commit. So it is still there and it is still too big. You need to delete commits all the way back to before you made the first “big” commit. Presumably you were unable to push after that, so nothing remote will be affected. Commented Nov 10, 2020 at 2:20
  • stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history Commented Nov 10, 2020 at 13:07

1 Answer 1

3

It probably wasn't Einstein who said that doing the same thing over and over and expecting a different result is insanity, but someone probably said it. And by all reports, that's what's happening here.

I committed and tried pushing a directory filled with large files.

git add . git commit -m "commit message" git push origin main 

I got an error that the files were too large.

Okay. So in the first step you recklessly added all your files to the index. In the second step you turned that in a commit. This is the Bad Commit. Let's call it The Bad Commit, shall we?

In the third step, you tried to push The Bad Commit but you couldn't. That's how you know it is a Bad Commit.

I then added the directory name to my .gitignore file and tried to push again.

I got the same error.

Yes, because changing your gitignore file has no effect on any existing commits. You still have The Bad Commit. You are still trying to push it and it is still Bad so you still get the same error.

I deleted the files in that repo both locally and remotely.

I'm not sure what that means, especially the "remotely" part. But I presume you deleted the files from the working tree, i.e. the files you can actually see. Notice that this is not a "repo". It's a working tree. You cannot see a repo, it is invisible. (Well, you could sort of "see" it if you wanted to, but even if you did you wouldn't see any files you could delete. And if you did manage to delete any merely by seeing them and trashing them directly, you would break the repo and that would be the end of the game.)

Okay, so let's take it that you saw some files that were big and you deleted them. So what? That has no effect on the Bad Commit.

I committed and tried pushing again but I got the same error.

But The Bad Commit is still sitting there. Okay, so now you have The Bad Commit plus some other commit, but The Bad Commit remains there and it remains Bad.

How can I clear out those commits with the large files so I can start pushing again without losing remote AND local work?

Delete them. How? Well, you are having regret Type 2. So use git log or git reflog to figure out the SHA number of the commit before The Bad Commit and say

git reset --mixed SHA 

That deletes The Bad Commit and the pointless commit you made after it, but leaves the work tree exactly as it is now. So now use git add more wisely and construct a good commit. Make the commit and push it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.