https://www.cnblogs.com/sunshine-xin/articles/3521481.html

1. git rm --cached file will remove the file from the stage. That is, when you commit the file will be removed. git reset HEAD -- file will simply reset file in the staging area to the state        where it was on the HEAD commit, i.e. will undo any changes you did to it since last commiting. If that change happens to be newly adding the file, then they will be equivalent.

意思是说:git rm -- cached 是从stage(index,暂存区) 里面删除文件,当你提交(commit)之后文件就会删除了。

git reset HEAD -- file : 回退暂存区里的文件(还原为HEAD commit里面该文件的状态),会撤销从上一次提交(commit)之后的一些操作。

如果是对于新增文件,这两个操作时等效的。

这两个命令都是对stage,index的操作。

2.  git rm --cached is used to remove a file from the index. In the case where the file is already in the repo, git rm --cached will remove the file from the index, leaving it in the working

directory and a commit will now remove it from the repo as well. Basically, after the commit, you would have unversioned the file and kept a local copy.

git rm --cached 作用: 从索引里删除文件。 如果要删除的文件已经在仓库里了,git rm --cached 将会从索引里删除该文件,但本地工作目录还会保存源代码,提交之后将会同时从仓库里删除该文件。

   git reset HEAD file ( which by default is using the --mixed flag) is different in that in the case where the file is already in the repo, it replaces the index version of the file with the one

from repo (HEAD), effectively unstaging the modifications to it.

git reset HEAD file (命令默认参数为 --mixed) 不同于文件已经在仓库中,该命令的作用是 用repo(HEAD)替换index中file的版本,使file的版本回退到HEAD版本,这个命令可以用于unstageing 对该文件的      改动。

3.  There are three places where a file, say, can be - the tree, the index and the working copy. When you just add a file to a folder, you are adding it to the working copy.

When you do something like git add file you add it to the index. And when you commit it, you add it to the tree as well.

It will probably help you to know the three more common flags in git reset:

git reset [--<mode>] [<commit>]

This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>, which must be one of the following:

--soft

Does not touch the index file nor the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

--mixed

Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

--hard

Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

Now, when you do something like git reset HEAD - what you are actually doing is git reset HEAD --mixed and it will "reset" the index to the state it was before you started adding files / adding modifications to the index ( via git add ) In this case, the working copy and the index ( or staging ) were in sync, but you made the HEAD and the index to be in sync after the reset.

git rm on the other hand removes a file from the working directory and the index and when you commit, the file is removed from the tree as well. git rm --cached however removes the file from index alone and keeps it in your working copy. This is the exact opposite of git add file In this case, you made index to be different from the HEAD and the working, in it that the HEAD has the previously committed version of the file, working copy had the las modification if any or content from HEAD of the file and you removed the file from the index. A commit now will sync the index and tree and the file will be removed.

git管理项目,有三个地方存放文件:the tree, the index and the working copy, (树,索引,工作目录/工作副本)。

当你向目录里添加一个文件的时候,这个文件存放在工作目录中。命令git add file 将文件添加到索引,当提交(coommit)的时候, 该文件也同时添加到了树中。

git reset命令有三种模式:git reset [--<mode>] [<commit>]  

该命令用来回退当前的分支head 到 <commit>, 根据<mode>不同 --soft --mixed --hard,会对working tree和index和HEAD进行重置, mode分为以下几种

1) --soft: 回退到某个版本,只回退了commit的信息,不会恢复到index file一级(对索引不做改动)。如果还要提交,直接commit即可,执行该模式之后,git status 对所有修改的文件会提示(Changes to be committed)

2) --mixed: 此为默认方式,不带任何参数的git reset,即是这种方式,它回退到某个版本,只保留源码,回退commit和index信息。

3)  --hard: 彻底回退到某个版本,本地的源码也会变为上一个版本的内容(所有的修改都会被丢弃)。

git rm 与 git reset的更多相关文章

  1. 第23月第24天 git命令 .git-credentials git rm --cached git stash clear

    在git push的时候,有时候我们会想办法撤销git commit的内容 1.找到之前提交的git commit的id git log 找到想要撤销的id 2.git reset –hard id ...

  2. git rm与git rm --cached

    当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用 git rm file_path git commit -m 'delete somefile' git push 当我 ...

  3. rm 、git rm 、git rm --cached的区别

    rm 删除文件 git rm git rm 当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用git rm git rm file = rm file+ git add f ...

  4. Git git rm和git rm --cached

    git rm 和 git rm --cached 的区别 git rm file git commit -m "xxx" git push origin master 删除本地及仓 ...

  5. git rm与git rm --cached的区别

    git rm与git rm --cached的区别 当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用. git rm file_path git commit -m 'd ...

  6. git命令——git rm、git mv

    git rm git rm命令官方解释 删除的本质 在git中删除一个文件,本质上是从tracked files中移除对这些文件的跟踪.更具体地说,就是将这些文件从staging area移除.然后c ...

  7. [转] git rm与git rm --cached

    当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用 git rm file_path 当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制 ...

  8. git rm 与 git rm --cached 的区别

    感谢原文作者:book_02 原文链接:https://www.jianshu.com/p/1c442fd398b7 git rm : 同时从工作区和索引中删除文件.即本地的文件也被删除了. git ...

  9. 移除文件(git rm)

    git rm`命令会把文件从已跟踪列表(及暂存区)中移除,并且移除把文件从工作目录中移除,这样下一次你就不会在未跟踪文件列表中看到这些文件了. 如果你只是简单的把文件从工作目录移除,而没有使用git ...

随机推荐

  1. 在Azure上通过Powershell创建多Interface的Cisco CSR路由器

    前面通过Json的Template在Azure上创建了Cisco的CSR路由器.但那个Json的template只支持1块网卡.如果需要多网卡的Cisco CSR路由器,可以改上篇文章中提到的Json ...

  2. Apache Htpasswd生成和验证密码

    Assuming you create the password using the following command and "myPassword" as the passw ...

  3. (转)Dynamic Web project转成Maven项目

    本文转载自:http://my.oschina.net/twosnail/blog/369125 1.新建Dynamic Web Project 1.File -> New -> Othe ...

  4. Make 命令

    Linux 下 make 命令是系统管理员和程序员用的最频繁的命令之一.管理员用它通过命令行来编译和安装很多开源的工具,程序员用它来管理他们大型复杂的项目编译问题.本文我们将用一些实例来讨论 make ...

  5. Py修行路 NumPy模块基本用法

    NumPy系统是Python的一种开源的数值计算扩展,一个用python实现的科学计算包.这种工具可用来存储和处理大型矩阵,比Python自身的嵌套列表(nested list structure)结 ...

  6. 部署和调优 2.1 squid正向代理

    安装squid yum install -y squid Squid 官方网站为 http://www.squid-cache.org 打开注释掉的 cache_dir ufs / 缓存目录的位置,大 ...

  7. Activity的显式跳转和隐式挑战

    安卓中Activity的跳转几乎是每一个APP都会用到的技术点.而且他的使用时十分简单的. 这里我们先说一下主要的技术要点: 1.在清单文件中注册新的Activity 2.通过意图跳转 这里我们看一下 ...

  8. Tornado之抽屉实战(2)--数据库表设计

    经过我们上次分析,数据库要有最基本的四张表,用户表,消息表,类型表,点赞表,评论表,接下来我们看着怎么设计吧 首先我们要清楚,表设计的代码是写在models下的 用户表 ? 1 2 3 4 5 6 7 ...

  9. Ajax入门(二)Ajax函数封装

    如果看了的我上一篇博客<Ajax入门(一)从0开始到一次成功的GET请求>的话,肯定知道我们已经完成了一个简单的get请求函数了.如下: 1234567891011121314151617 ...

  10. go语言的基本命令

    go run命令: 用于运行命令源码文件 只能接受一个命令源码文件以及若干个库源码文件作为文件参数其内部操作是:先编译源码文件在执行 -v:列出被编译的代码包的名称 -work: 显示编译时创建的临时 ...