miwoe
miwoe

Reputation: 787

Delete file(s) from git repository without deleting it from local filesystem of all local filesystem

I have made a mistake. I added a file to a git repository which should be deleted.

Ok, this question was asked multiple times on SO. The solution is:

git rm (-r) --cached myfiletodelete 

If I do this, the file is not deleted on MY local system. But, if colleagues do a PULL, the file is deleted on their system.

How can I avoid this? In other words, I want to delete the file only in 'origin', but not in any other local repository and then put it on gitignore.

Upvotes: 0

Views: 43

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 97004

It’s not possible to have Git do this for you (short of setting up Git hooks on every machine—not a good solution here). git pull is getting the latest changes, and those changes include deleting that file. You’ll have to instruct others to manually put the file back. You’d have to provide some way for others who are pulling for the first time to get it as well anyway, so just instruct them in the same manner.

Upvotes: 2

Related Questions