I'm still trying to fully learn Git, but after searching I'm still a bit confused. I removed the file from the Git repository using git rm --cached
and the file remains locally. Upon pushing to the remote git repository and pulling it on the developmental server, the file that I removed is deleted. Could someone please suggest how to fix this?
Asked
Active
Viewed 77 times
1
-
1fix what? what are you expecting – Xiaotian Pei Jul 02 '15 at 17:05
-
Related: http://stackoverflow.com/q/1139762/1157054 – Ajedi32 Jul 02 '15 at 17:32
-
Do you want to delete those files? – mayo Jul 02 '15 at 18:12
-
To make it clear, I'm trying to remove my wp-config.php from my repository as it is different on my computer and my development server. I want to have 2 different copies of the file, but when I ran git rm --cached, it kept a copy on my computer, but when I pulled to my server, the file was deleted. – SVAN Jul 02 '15 at 18:28
2 Answers
1
There are 3 areas you need to consider: the repository, the staging area and the workspace.
- git rm removes from the staging area and the workspace
- git rm --cached removes from the staging area only. It only gets removed from the workspace when you commit.
The file still remains in the repository. If you get a version of the repository before the file was removed, you will get the file back.

cup
- 7,589
- 4
- 19
- 42
-
To escalate the example, you can erase the file from the whole history: `git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch FILES" HEAD`. Be careful with this! – ikrabbe Jul 02 '15 at 17:10
-
To make it clear, I'm trying to remove my wp-config.php from my repository as it is different on my computer and my development server. I want to have 2 different copies of the file, but when I ran git rm --cached, it kept a copy on my computer, but when I pulled to my server, the file was deleted. – SVAN Jul 02 '15 at 17:13
0
git rm <Insert File name>
git commit --cashed <File name>
The first one removes it from the workspace and index. Cached will only remove it from the index. If you forget to commit then it will stay in the workspace.

Sean Stinehour
- 71
- 6