0

I have added several files by mistake with

git add <file name>

Then I have run

git commit -m '..'

However, some files where too big and it failed when I run git push - now I'm stuck and I can't unstage those big files.

I've tried with 'git reset', 'git rm' but every time I try to push these big files reappear! How do I reset everything?

Alex
  • 1,447
  • 7
  • 23
  • 48
  • 1
    Could you run 'git status' and show us the output? – NewEyes Mar 27 '19 at 20:17
  • 1
    If the commit succeeded (`git log` shows the new entry), `git reset HEAD^` will uncommit it without touching the working tree. – Petr Skocik Mar 27 '19 at 20:17
  • git reset HEAD^ doesn't work. when I push again these big files are still there – Alex Mar 27 '19 at 20:19
  • Were those files first added in the most recent commit? – ChrisGPT was on strike Mar 27 '19 at 20:20
  • yes - since I've added I haven't been able to get rid of them. – Alex Mar 27 '19 at 20:22
  • 1
    Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – phd Mar 28 '19 at 00:06
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+files+history – phd Mar 28 '19 at 00:06
  • How big are those files that are stuck, you can try this: `git config http.postBuffer 524288000`. This sets the buffer size to 500mb, this might help in pushing those big files to the repo. [Here](https://stackoverflow.com/a/15851500/7639034) is a stackoverflow answer that might help you solve this. – Code_Ninja Mar 28 '19 at 08:48

1 Answers1

1

Normally what you do in this cases is amend the revision you created to remove the files..... so if you have created revisions after that revision where you added thenm, it won't work because those files are already part of the history of the project.... so, go back to the revision where you added them by mistake (use the ID), rm --cache those files and amend. Then you could push into the remote.

git checkout id-of-the-revision-where-I-added-the-files
git rm --cache file1 file2 file3 etc
git commit --amend --no-edit
# if everything is fine, move the branch pointer and push
git branch -f my-branch
git checkout my-branch
git push some-remote my-branch

That should be good enough

eftshift0
  • 26,375
  • 3
  • 36
  • 60