zoukankan      html  css  js  c++  java
  • git rm与直接rm的区别

    git rm

    行为:

      1.删除一个文件

      2.将被删除的这个文件纳入缓存区

    $ git rm a
    rm 'a'
    $ git status
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            deleted:    a

    提交:

      直接 git commit -m ''

    $ git commit -m 'delete a'
    [master 1cd6efe] delete a
     1 file changed, 0 insertions(+), 0 deletions(-)
     delete mode 100644 a
    
    $ git status
    On branch master
    nothing to commit, working directory clean

    恢复:

      1. 恢复暂存区

      2. 恢复工作区

    $ git reset HEAD a
    Unstaged changes after reset:
    D       a
    
    $ git status
    On branch master
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
            deleted:    a
    
    no changes added to commit (use "git add" and/or "git commit -a")
    
    $ git checkout -- a
    $ git status
    On branch master
    nothing to commit, working directory clean

    直接调用系统的rm

    行为:

      从工作区删除了一个文件

    $ rm a
    
    $ git status
    On branch master
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
            deleted:    a
    
    no changes added to commit (use "git add" and/or "git commit -a")

    提交:

      1.把修改加入暂存区

      2.提交暂存区的改动

    $ git add a
    
    $ git status
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            deleted:    a
    
    $ git commit -m 'delete a '
    [master 689a73d] delete a
     1 file changed, 0 insertions(+), 0 deletions(-)
     delete mode 100644 a
    
    $ git status
    On branch master
    nothing to commit, working directory clean

    恢复:

      直接恢复工作区就好了,git checout -- file

    $ git checkout -- a
    
    $ git status
    On branch master
    nothing to commit, working directory clean

      

  • 相关阅读:
    通过Maven简单搭建SSM框架
    javaWeb常用面试题
    到底什么是对象,什么是对象的引用?对象和对象的引用有那些区别?
    第二章 python中重要的数据结构(下)
    第一章 python中重要的数据结构(上)
    springboot 集成完整的swagger2
    JAVA -> 数据加密和解密 留存
    mac rar文件解压缩
    java 图片合成文字或者awt包下的对话框引入自定义字体库
    java中list或数组中随机子集工具类
  • 原文地址:https://www.cnblogs.com/413xiaol/p/10554724.html
Copyright © 2011-2022 走看看