1

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?

4
  • 1
    fix what? what are you expecting Commented Jul 2, 2015 at 17:05
  • Related: stackoverflow.com/q/1139762/1157054 Commented Jul 2, 2015 at 17:32
  • Do you want to delete those files? Commented Jul 2, 2015 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. Commented Jul 2, 2015 at 18:28

2 Answers 2

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.

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

2 Comments

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!
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.
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.

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.