git rm --cached和git reset< file>有什么区别? [英] What is the difference between git rm --cached and git reset <file>?

查看:1122
本文介绍了git rm --cached和git reset< file>有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 git rm文档

   -  cached 
使用此选项可以仅从索引中取消并删除路径。
无论是否修改工作树文件,都将被单独保留。

但根据此资源使用

  git reset HEAD< file> 

有什么区别? 要删除的文件,但不要将其从工作目录中删除。该文件将显示为未跟踪。



参加试驾活动

  git init test_repo 
cd test_repo

touch test
git add test
git commit -m'新增文件测试

git rm - 缓存测试

git status
要提交的更改:
(使用git reset HEAD< file> ...停用)

删除:测试< ----为删除而暂存

未记录的文件:
(使用git add< file> ...来包含将要提交的内容)

test< - 仍在工作目录中

使用 git reset< file> 你可以取消一个文件。在上面的示例中,您可能希望使用 git reset test 来取消删除操作。

  git重置测试
git状态
在分支大师
上没有提交,工作目录干净


According to the git rm documentation,

--cached
Use this option to unstage and remove paths only from the index.    
Working tree files, whether modified or not, will be left alone.

But according to this resource unstaging a file is done with

git reset HEAD <file>

What is the difference? Is there one?

解决方案

With git rm --cached you stage a file for removal, but you don't remove it from the working dir. The file will then be shown as untracked.

Take a test drive

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

With git reset <file> you can unstage a file. In the example above you might want to use git reset test to unstage the removal.

git reset test
git status
On branch master
nothing to commit, working directory clean

这篇关于git rm --cached和git reset&lt; file&gt;有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆