What does git-rm mean by working tree and index?

岁酱吖の 提交于 2021-02-08 08:18:52

问题


The documentation for git-rm contains this short description:

git-rm - Remove files from the working tree and from the index

What exactly is meant by the working tree and the index, and which local or remote files will be removed?


回答1:


The "working tree" is your checkout of the files sitting on disk.

The "index", "staging area", or "cache" (you'll see it referred to as all three) is internal to Git. It's the space you prepare the next commit. When you git add you're copying the files from the working tree to the staging area. When you git commit you're committing what's in the staging area.

git rm removes files from both the working tree and the staging area (unless you tell it to just remove from the staging area with --cached).

This cheat sheet might help you understand the relationship between the working tree, staging area, and HEAD (the currently checked out commit). More importantly, it tells you how to manipulate them because the commands are really not-intuitive.




回答2:


It means removing from working tree: the working directory of your file system tree where you cloned this repository and from index in .git directory maintained by git. git rm will never remove the file from working directory alone otherwise it will leave index database in inconsistent state. To inform index database about removal of files using Unix based rm command, you're required to run git commit -a which essentially removes the index of deleted objects.



来源:https://stackoverflow.com/questions/43095440/what-does-git-rm-mean-by-working-tree-and-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!