I committed some files that I shouldn't commit. Then I added these files in .gitignore and I did this:
git rm -r --cached somefile
and I committed again.
git status
shows:
# On branch experiment
nothing to commit, working directory clean
I do git ls-files
and these files are not listed.
But when I do git push origin somebranch
, these files are still being pushed (they're too large to push to github so it fails).
why is this? what should I do?
The files are still in your git history. From what's in the question the git history is for example:
$ git log --oneline
aaaaaaa Update .gitignore and remove big files
bbbbbbb accidentally add big files to repo
ccccccc update foo
ddddddd update bar
And pushing fails because of pushing the contents of commit bbbbbbb
, it doesn't matter that the file is not in your currently checked out version it's in the project history.
The above can also be confirmed by checking for the history of a specific file/path:
$ git log --all --format=%H -- big.file
aaaaaaa Update .gitignore and remove big files
bbbbbbb accidentally add big files to repo
If big.file
is large enough to prevent pushing to github - you need that list of commits to be empty
There are a number of ways to prevent attempting to push big.file
to the remote, but based on the info in the question the simplest of which is:
$ git reset --hard ccccccc
This will remove commits aaaaaaa
and bbbbbbb
thus there will be no attempt to push big.file
to the remote.
.gitignore
files affect adding files to the repository, they do not affect files already in the index. This is the reason that adding files to .gitignore
has had no effect on 'the problem'.
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