0

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.

1
  • 1
    You can’t. Removing the file from Git adds a “removal step” that is carried out when the commit is checked out. So the file is removed. Commented Jan 31, 2017 at 14:10

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.