zoukankan      html  css  js  c++  java
  • git 删除文件

    在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交

    [root@node1 git]# git add test.txt 
    [root@node1 git]# git commit -m "add test.txt"
    [master d96c047] add test.txt
     1 file changed, 2 insertions(+)
     create mode 100644 git/test.txt

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

    [root@node1 git]# rm test.txt -r

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

    [root@node1 git]# 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:    test.txt
    #
    no changes added to commit (use "git add" and/or "git commit -a")

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

    [root@node1 git]# git rm test.txt 
    rm 'git/test.txt'
    [root@node1 git]# git commit -m "remove test.txt"
    [master 8bb540d] remove test.txt
     1 file changed, 1 deletion(-)
     delete mode 100644 git/test.txt

    现在,文件就从版本库中被删除了

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

    [root@node1 git]# git checkout -- test.txt

    git checkout其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。

    小结

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

  • 相关阅读:
    发布spring cloud + vue项目
    以太坊上发行ERC20代币
    [转]大白话讲解Promise(一)
    比特币测试网络搭建
    非对称加密, 助记词, PIN, WIF
    搭建EOS未完
    [转]EOS智能合约 & 私链激活 & 基本操作
    [转]https://www.jianshu.com/p/06443248f4d8
    web3js 进行转账
    [转]How to Send Ethereum with Web3.js and Node
  • 原文地址:https://www.cnblogs.com/wanglan/p/7452148.html
Copyright © 2011-2022 走看看