$ git init
Initialized empty Git repository in .git/ $ echo "testing reset" > file1
$ git add file1
$ git commit -m 'added file1'
Created initial commit 1a75c1d: added file1
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 file1 $ echo "added new file" > file2
$ git add file2
$ git commit -m 'added file2'
Created commit f6e5064: added file2
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 file2 $ git reset --hard HEAD^
HEAD is now at 1a75c1d... added file1 $ cat file2
cat: file2: No such file or directory $ git reflog
1a75c1d... HEAD@{0}: reset --hard HEAD^: updating HEAD
f6e5064... HEAD@{1}: commit: added file2 $ git reset --hard f6e5064
HEAD is now at f6e5064... added file2 $ cat file2
added new file

Recover a file when you use git reset head by mistake.的更多相关文章

  1. Recover a file even if it was not committed but it has to have been added when you use git reset head by mistake.

    git init echo hello >> test.txt git add test.txt Now the blob is created but it is referenced ...

  2. git rm 与 git reset

    https://www.cnblogs.com/sunshine-xin/articles/3521481.html 1. git rm --cached file will remove the f ...

  3. git分布式版本控制系统权威指南学习笔记(六):git reset、get stash、git checkout总结

    文章目录 1. 概述 2. 如何把修改暂存起来,留着以后使用? 2.1 使用场景 2.2 git stash 暂存进度 2.3 查看进度 2.4 恢复进度 3. 如何撤销工作区的修改? 4. 如何把暂 ...

  4. 如何理解git checkout -- file和git reset HEAD -- file

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374831943254ee ...

  5. git reset --soft --hard 区别

    [转]git reset 之 soft mixed hard选项的区别 (2014-09-09 16:54:06) 转载▼ 标签: git 分类: Linux 译注:为了避免丢失本地的修改以及orig ...

  6. [译]git reset

    git reset 如果说git revert是一个安全的撤销方式, 那么git reset就是一个非常危险的方法了. 当你使用git reset撤销的时候, 你没有可能在回到最初了-他是一个永久的不 ...

  7. git reset soft,hard,mixed之区别深解

    GIT reset命令,似乎让人很迷惑,以至于误解,误用.但是事实上不应该如此难以理解,只要你理解到这个命令究竟在干什么. 首先我们来看几个术语 HEAD 这是当前分支版本顶端的别名,也就是在当前分支 ...

  8. 撤销 git reset --hard HEAD~1

    方法一: 1.先通过git reflog找到上一次的历史提交记录id,git如果没有特意设置,是会保存记录一段时间的(a few days or a month) 2.git reset --hard ...

  9. git reset到之前的某一个commit或者恢复之前删除的某一个分支

    一.使用了git reset之后,想要找回某一个commit 1.git log -g  这个命令只能显示少部分的commit 推荐使用git reflog 找到想要恢复的那个commit的hash, ...

随机推荐

  1. react中createFactory, createClass, createElement分别在什么场景下使用,为什么要这么定义?

    作者:元彦链接:https://www.zhihu.com/question/27602269/answer/40168594来源:知乎著作权归作者所有,转载请联系作者获得授权. 三者用途稍有不同,按 ...

  2. Oracle EBS-SQL (PO-16):检查采购订单完成情况统计.sql

    select         e.FULL_NAME                                                     采购员,         sum(plla ...

  3. QT Creator 2.7.2 代码自动补全快捷键设置

    在QT Creater界面点[工具]再进[选项]找到[环境]下的[键盘]选项,搜索[CompleteThis]发现默认快捷键就是CTRL+SPACE,把它删除,然后添加自己想设置的快捷键(因为之前用e ...

  4. NFC协议学习分享

    很多同学在学习NFC协议的时候,觉得NFC的规范从底层到上层的应有尽有,有点无处下手的感觉.这里就和大家分享下我曾经学习NFC规范的经验.如果有不对的地方,也请各位同学批评指正.NFC Forum中有 ...

  5. 【JavaScript】Object.prototype.toString.call()进行类型判断

    权声明:本文为博主原创文章,未经博主允许不得转载. op = Object.prototype, ostring = op.toString, ... function isFunction(it)  ...

  6. c# 数据导出成excel 方法总结 见标红部分

    public void ServiceOrderExport(string data) { StringBuilder sb = new StringBuilder(); Type entityTyp ...

  7. OSCHina技术导向:Java电子商务平台OFBiz

    OFBiz 是开放的电子商务平台,是一个非常著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级.跨平台.跨数据库.跨应用服务器的多层.分布式电子商务类WEB应用系统的框 ...

  8. SQLite.dll混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。

    其他信息: V5.7.4.4 Can't find the System.Data.SQLite.dll more info : 混合模式程序集是针对"v2.0.50727"版的运 ...

  9. Hibernate问题之'hibernate.dialect' not set

    继前文:Hibernate4中buildSessionFactory方法废弃问题.后 继续有问题.本来之前好好的项目,用了这种新的方法后发现问题. 出现  Connection cannot be n ...

  10. OAuth2.0 错误码

    http://open.taobao.com/doc/detail.htm?id=118 OAuth2.0 错误码 新浪微博OAuth2.0实现中,授权服务器在接收到验证授权请求时,会按照OAuth2 ...