How to delete/remove files from a pushed commit?
Mia Lopez
is it possible to delete/remove some unwanted files from remote and local repository?
I was a bit to fast and pushed 5 files to the remote repo. Now my colleague pushed his work and saw to late these unwanted files. So now there are 2 commits after my 'wrong' commit.
I tried to use
git rebase -i HEAD~3and changed the first entry to "edit" and deleted that unwanted files. Next I used
git commit --amend
git rebase --continueBut GIT wont finalize it. It always said that I'm at the last commit and there is a rebase in progress. But I'm not able to continue to finish it.
2 Answers
You can easily remove unwanted files from local git repositories:
Just remove them withgit rm file
orgit rm -r directory (if you add the --cached-flag the file doesn't get removed from your filesystem). Then commit (or commit --amend) to remove the file from the last commit (it stays in in the history, though). See also here
If you want to remove it from a remote repo follow the same steps and push afterwards.
2git rm file
git commit --amend
git push origin HEAD:refs/for/develop