根据git rm文档,
--cached
Use this option to unstage and remove paths only from the index.
Working tree files, whether modified or not, will be left alone.
Run Code Online (Sandbox Code Playgroud)
但是根据这个资源, unstaging文件完成了
git reset HEAD <file>
Run Code Online (Sandbox Code Playgroud)
有什么不同?有吗?
Gre*_*egg 13
git rm --cached 从索引中删除文件,但将其保留在工作目录中。这向 Git 表明您不想再跟踪该文件。
git reset HEAD 将文件作为索引中的跟踪文件保留,但索引中缓存的修改会丢失。这的效果就像缓存中的文件已被 HEAD 中的文件覆盖(并且工作树文件未受影响)
随着git rm --cached
您阶段去除一个文件,但你没有从工作目录中删除.然后该文件将显示为未跟踪.
试驾
git init test_repo
cd test_repo
touch test
git add test
git commit -m 'Added file test
git rm --cached test
git status
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
deleted: test <---- staged for removal
Untracked files:
(use "git add <file>..." to include in what will be committed)
test <-- still in the working dir
Run Code Online (Sandbox Code Playgroud)
有了git reset <file>
你可以unstage文件.在上面的示例中,您可能希望用于git reset test
取消删除删除.
git reset test
git status
On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)