Reputation: 12343
I have never encountered this problem before and have no idea how this is possible. I had a really large directory that I downloaded by mistake into my git repo. I inadvertently did a git add .
so the large directory got added to the working tree and when I tried to commit, it didn't allow me to, as the file was too big.
Then I didn't do a git rm
and directly removed the file from the filesystem. The next time I tried to commit, it didn't allow me to and is still complaining that the directory (which is now no longer present on the filesystem) is too big.
Doesn't removing a file from the filesystem also remove it from the git working tree?
If there is a way to undo my last 2 commits without losing changes,and then re-push it to remote, that would be great.
Upvotes: 4
Views: 6018
Reputation: 157947
You need to remove it from the index before the commit:
git rm --cached FOLDER_NAME
Since you have it already removed from the file system, the folder should have disappeared now.
If you have added the folder in the most recent commit then you can simply issue:
git commit --amend
git push -f REMOTE BRANCH_NAME
If you have added the folder in penultimate commit, things get a little bit more difficult. I suggest to create a backup of the local repo first.
Follow these steps:
# Rebase the second most recent commits
# -i will open an editor
git rebase -i HEAD~2
In the editor replace pick
by edit
in the line with the second last commit and save the file. You can now change that commit. Issue:
git rm FOLDER_NAME
# This will open an editor again. You can leave the
# commit message unchanged. Simply save the file
git commit --amend
# Finish the rebase action
git rebase --continue
Now you should be done and the folder is removed from that commmit. You can push using
git push REMOTE BRANCH_NAME
Upvotes: 4