Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How to delete/remove files from a pushed commit?

Writer 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~3

and changed the first entry to "edit" and deleted that unwanted files. Next I used

git commit --amend
git rebase --continue

But 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 with
git rm file
or
git 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.

2
git rm file
git commit --amend
git push origin HEAD:refs/for/develop

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy