git 删除文件后如何恢复[通俗易懂]

git 删除文件后如何恢复[通俗易懂]有时候不小心在git中rm了文件。怎么恢复呢?别急,咱们一步步来。首先gitstatus一把,看看此时工作区的状态[xxx@xxxstatic_files]$gitstatus#Onbranchmasternothingtocommit(workingdirectoryclean)可见此时没有任何修改的内容。再看看具体有什么xxx@xxxstatic_files]$

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

项目github地址:bitcarmanlee easy-algorithm-interview-and-practice
欢迎大家star,留言,一起学习进步

有时候不小心在git中rm了文件。怎么恢复呢?别急,咱们一步步来。

首先git status一把,看看此时工作区的状态

[xxx@xxx static_files]$ git status
# On branch master
nothing to commit (working directory clean)

可见此时没有任何修改的内容。
再看看具体有什么

xxx@xxx static_files]$ ls
abbr_data  breakfast_data  room_type_data

此时总计有三个文件。OK,让我们干掉其中一个

[xxx@xxx static_files]$ git rm abbr_data
rm 'static_files/abbr_data'
[xxx@xxx static_files]$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	deleted:    abbr_data
#
[xxx@xxx static_files]$ ls
breakfast_data  room_type_data

此时工作区的文件就只剩两个了,abbr_data这个文件,已经被我们干掉。

如果我们想要恢复,怎么办呢?

[xxx@xxx static_files]$ git checkout -- abbr_data
error: pathspec 'static_files/abbr_data' did not match any file(s) known to git.

直接checkout,是不行的。
那怎么办呢?其实在git status中,已经告诉我们怎么办了。

[xxx@xxx static_files]$ git reset HEAD abbr_data
Unstaged changes after reset:
M	static_files/abbr_data

用reset命令,先将abbr_data这个文件找回来。

[xxx@xxx static_files]$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	deleted:    abbr_data
#
no changes added to commit (use "git add" and/or "git commit -a")

再checkout一把

[xxx@xxx static_files]$ git checkout -- abbr_data
[xxx@xxx static_files]$

看到checkout以后没有任何提示,这事就成了。因为git的哲学跟unix的哲学一样,没消息就是最好的消息。。。

再ls一下,果然,abbr_data找回来了。

[xxx@xxx static_files]$ ls
abbr_data  breakfast_data  room_type_data
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/172143.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Matlab机器人工具箱

    Matlab机器人工具箱因为需要用到和机器人相关的东西,就用到了这个工具箱,作者官网http://www.petercorke.com/Robotics_Toolbox.html文章开头有我上传的机器人工具箱链接,有需要的同学可以自行下载。CSDN下载积分不能设置为0,抱歉~没有积分的同学可以去官网下载搞定。老爷子很厉害,那本《Robotics,Vision&Control》就是他本人写的,可…

    2022年4月30日
    56
  • Selenium WebDriver下载与安装[通俗易懂]

    Selenium WebDriver下载与安装[通俗易懂]1.python(anaconda环境)condainfo–envsactivateuntitled2.pip/condainstallselenium3.seleniumdriver(放在anaconda环境path中)Chrome(32位)http://chromedriver.storage.proxy.ustclug.org/index.htmlFire…

    2022年9月19日
    2
  • struts2 核心控制器:FilterDispatcher (写的真心清晰)

    struts2 核心控制器:FilterDispatcher (写的真心清晰)原文:http://mopishv0.blog.163.com/blog/static/54455932200981295843192/ 1.    在 struts1.x 系列中 , 所有的请求是通过一个 servlet(ActionServlet) 来管理控制的 , 在 Struts2.X 而是经过一个Filter 来处理请求的。 Struts2 将核心控制器设计成 Filt

    2022年8月16日
    9
  • StringBuilder详解「建议收藏」

    StringBuilder详解「建议收藏」1、简介StringBuilder和StringBuffer一样,都是继承自抽象类AbstractStringBuilder类,也是一个可变的字符序列。StringBuilder和StringBuffer非常相似,甚至有互相兼容的API,不过,StringBuilder不是线程安全的,这是和StringBuffer的主要区别。StringBuilder的层次结构如下:StringB

    2022年6月28日
    21
  • allure command

    allure commandallure-Usage:allure[options][command][commandoptions]Options:–helpPrintcommandlinehelp.-q,–quietSwitchonthequietmode.Default:false-v,–verboseSwitchontheverbosemode.Default:false…

    2022年7月26日
    7
  • SpringMVC @ResponseBody 415错误处理

    SpringMVC @ResponseBody 415错误处理闲话少说,刚开始用SpringMVC,页面要使用jquery的ajax请求Controller。但总是失败,主要表现为以下两个异常为:异常一:java.lang.ClassNotFoundException:org.springframework.http.converter.json.MappingJacksonHttpMessageConverter异常二

    2022年6月10日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号