I have removed the offending file, but the commit still has it as part of the commit.
This is a job for git rebase
. Specifically, I think you want the -i
interactive option, which allows you to remove one or more commits in the history, reorder commits, edit individual commits, etc. For example, you could:
git log
to see the commits;
git rebase -i <hash of the commit prior to adding the big file>
to start the rebase process. This will open an editor and show you a list of commits back to the one you specified, along with commands for each. It's a powerful tool and you should read more extensive instructions than I'm giving here, but for example you could edit the commit where you added the big file by changing pick
for that commit to edit
. git rebase
will then replay the commits, stopping on the commit you want to edit. You can delete the file and 'git add' it, and then git rebase continue
to replay the rest of the commits. After that, the file should have been removed from the history.
The standard warning applies: rebase
is a powerful command that can really screw up your git history, so be very careful with it. When in doubt, make a copy of your branch beforehand so that you can get back to your current state.