4

So I'm fairly new to git and I've gotten in a bit of a pickle.

I have many new changes to my local copy that conflict with my github repo (however my local copy is correct and I'd like to just overwrite the remote repo). The local and remote copy have diverged by 2 and 3 commits.

I also accidentally added a few very large csv files to my local commit and now I am unable to push to the remote repo with git push -f because github rejects the large files.

Now I deleted the files and removed them from the commit with git rm --cached "filename.csv" and git commit --amend -CHEAD and they are no longer in the commit as far as I can tell from git ls-files | grep "*.csv" which returns blank.

However when I try to use git push -f now after they are no longer tracked, github still detects them and rejects my push because they are too large although they are no longer on the filesystem or in the commit.

How can I push the local copy to overwrite the remote and get the push to realize I no longer have the large files?

Thanks in advance for any and all git advice... it can be a bit confusing for a newbie.

Taaam
  • 1,098
  • 3
  • 11
  • 23
  • commit one more time and push the code. – Anjaneyulu Battula Oct 19 '14 at 02:39
  • Check that they aren't still in a commit *other* than the most recent one. `git whatchanged` is a good way to check. If so, `git rebase -i lastgoodcommit`. – o11c Oct 19 '14 at 02:47
  • Committing one more time didn't work. As for the rebase, whatchanged shows that the files were added in the previous commit, and then deleted for this commit, but by `lastgoodcommit` do you mean that I revert to the snapshot before the files were ever added? Wouldn't that make me lose the work I've done since then? – Taaam Oct 19 '14 at 03:08
  • `git rebase -i HEAD~2`, change line 1 `pick` to `edit`, `git reset HEAD^`, `git rm --cached "filename.sv"`, `git commit`. – Andrew C Oct 19 '14 at 03:22
  • oh and then `git rebase --continue`. That should be all you need to nuke the file in this instance – Andrew C Oct 19 '14 at 03:23

1 Answers1

6

Sounds like you have committed the large file, then made another commit that deletes the large file. That means that the large file is still in one or more earlier commits. When you push to GitHub, you're pushing the whole repository, with all commits (including any that have the large file). GitHub is actually rejecting one of the older commits because of the large file.

The reason you can't see the file with git ls-files is that it only lists the files in the current index (the last commit, and changes your're about to commit) and working tree (the current state of the files on disk), not all files in the repository's history.

To fix the problem, you can follow the steps on How to remove/delete a large file from commit history in Git repository?. That way you can make it as though you never committed the file.

Community
  • 1
  • 1
Daniel
  • 10,115
  • 3
  • 44
  • 62