I know this has been asked and discussed earlier, but I couldn´t find the right workflow for this problem.
Let´s say I´m working on a new project that I want to push to GitHub. After a few commits and pushes that worked well, I continue coding and editing and at some point I add some big files larger than 100MB to my project (without knowing or keeping in mind that this will cause problems when I will try to push it in the next step).
So I do:
git add .
and after that I do:
git commit -m 'some commit message'
and finally:
git push
And now I am in trouble, because I get the remote error: Large files detected.
So what are my options here to 1. keep my project changes and my added files alive and 2. exclude the big files files from future commits.
I have found the command to delete the last commit (where I added the big files among other things) with git revert …
, but this is not want I want, because it also deletes all the work from my working directory.
This achieves the same effect as Joe A's answer except its a lot simpler and in my view it's a lot safer for someone unfamiliar with the area.
git reset --soft HEAD~
This will undo the commit but leave all the things that would have been committed as staged.
Then git rm
the files that shouldn't have been committed and then re-commit.
Now you should be able to push.
Note there is nothing technically wrong with Joe's answer and I have upvoted it; it's just overkill and overly complicated for such a simple problem. However if your commit chain included n>1 commits Joe's answer would be your best option. So this is more like a special case where you can do somethign safer since it was just your last operation that was problematic.