I have accidentally added and committed a (huge) log file into my local git repository and then did a git rm (without --cached). So the history looks like this:
> git status
modified:  Foo.java
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    huge_file.log
nothing added to commit but untracked files present (use "git add" to track)
Then I did git add .:
> git add .
> git status
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    modified:  Foo.java
    new file:   huge_file.log
Then (I have overlooked that I've added huge_file.log) I did a git commit:
> git commit -am "Foo commit"
[master 7582793] Foo commit
 1 file changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 huge_file.log
Then I realized that I have added and committed  huge_file.log. So I thought I could undo that by doing git rm huge_file.log:
> git rm huge_file.log
> git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    deleted:    huge_file.log
So at this point, I realized the mess I made: I can't commit and push to master this changes because that would mean pushing huge_file.log and then deleting huge_file.log. Unfortunately, I can't push since we have a file limit of 100 MB per file and huge_file.log is more than 1 GB. 
So what can I do now? I can't simply reset HEAD to a previous commit since I have made a lot of changes in Foo.java that I don't want to undo.
Is there a way to change the previous commit to remove huge_file.log somehow.
Please note that Foo.java is just representative for better readability here on StackOverflow. I have touched about 10 files and modified many lines of code in each file, and I don't want to lose this changes.
What should I do now?
If it's just in the last commit, 
then do git rm huge_file.log and then git commit --amend.
Git allows you to make amends for the last error you've committed. Literally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With