简体   繁体   中英

Delete file from Git

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM