zoukankan      html  css  js  c++  java
  • git教程学习笔记(6)

    git教程学习来自廖雪峰的官方网站

    删除文件

    先新建一个test.txt文件提交到git

    $ git add test.txt
    
    $ git commit -m "add test.txt"
    [master b84166e] add test.txt
     1 file changed, 1 insertion(+)
     create mode 100644 test.txt

    一般情况下,你通常直接在文件管理器中把没用的文件删了,或者用rm命令删了:

    $ rm test.txt

    这个时候,Git知道你删除了文件,因此,工作区和版本库就不一致了,git status命令会立刻告诉你哪些文件被删除了:

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

    现在你有两个选择,一是确实要从版本库中删除该文件,那就用命令git rm删掉,并且git commit

    $ git rm test.txt
    rm 'test.txt'
    
    $ git commit -m 'remove test.txt'
    [master e9927e4] remove test.txt
     1 file changed, 0 insertions(+), 0 deletions(-)
     delete mode 100644 test.txt

    另一种情况是删错了,因为版本库里还有呢,所以可以很轻松地把误删的文件恢复到最新版本:

    $ git restore test.txt

     注意:从来没有被添加到版本库就被删除的文件,是无法恢复的!

    命令git rm用于删除一个文件。如果一个文件已经被提交到版本库,那么你永远不用担心误删,但是要小心,你只能恢复文件到最新版本,你会丢失最近一次提交后你修改的内容

  • 相关阅读:
    Chrome截屏-截取当前页
    SecureCRT 工具分享
    mongodb在shutdown时报错:shutdown must run from localhost when running db without auth
    gdb如何实现info vtbl命令
    aspose.word 替换图片
    字节跳动校招+社招
    Flink日志输出配置
    Kafka高可用及高性能原因
    基于SAAS模式的客服云平台落地实践
    代码Recode
  • 原文地址:https://www.cnblogs.com/LeoXnote/p/11460917.html
Copyright © 2011-2022 走看看