If the commit that introduced the file is called <bad> (locates it with a git log --stat
), reconstruct your history from the commit before <bad> (I assume you’re in the branch that introduced the bad commit):
git rebase -i <ruim>~1
A text file will appear in a file editor. It lists all commits you use to redo history (an interactive rebase) from the bad commit (first line). You have to decide what to do. 2 possibilities:
1- The <bad> commit contains only the introduction of the bad file (and nothing else). You just have to delete the line with the bad commit in the file. Save the file, close the editor, let the history do again without the bad commit, and git push
in the end.
2 - The <bad> commit contains the introduction of the bad file and other things you want to talk about. Replace the commit line like this:
pick <ruim> Mensagem do commit
in:
edit <ruim> Mensagem do commit
Saves the file and closes it. git will redo the history by stopping after the bad commit. Wait until the rebase pause, and:
git reset HEAD~1 # cancelar commit ruim
git status # ver que arquivos introduzir no commit
git add <arquivos que conservar>
...
rm <mau arquivo>
git commit -m "Mensagem do commit" # refazer commit
git rebase --continue # aplicar os commits seguintes se tem mais no rebase
git push
You can do
git reset --soft HEAD^1
, by removing commits until the one you don’t want (in case you don’t have commits in the remote yet).– Sergio
Complaining how? What was the message?
– Dherik
he complains about the size of the file passed 140mb (which is precisely the file I accidentally played in a commit), so now I wanted to find some way to delete this commit in order to be able to push pro
– Victor Siqueira
I already have commit on the remote, never did a rebase, some problem?
– Victor Siqueira