$ 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. SQL Server 连接和事务相关的问题。

    方法 1. dbcc opentran + sys.dm_exec_connections dbcc opentran; dbcc opentran 针对当前数据库 dbcc opentran('St ...

  2. SQL Server 提高创建索引速度的 2 个方法

    方法 1. 使用tempdb来提速 create index index_name on table_name (column_list) with(sort_in_tempdb = on); 方法 ...

  3. cf459B Pashmak and Flowers

    B. Pashmak and Flowers time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. java MongoDB driver error infos

    DataTables warning: table id=dateTable - Ajax error. For more information about this error, please s ...

  5. 电脑中已有VS2005和VS2010安装.NET3.5失败的解决方案

    1.重启 MSI 安装服务: 运行-输入“CMD”命令,在弹出的对话框中输入命令: msiexec/unregserver ,回车,并再次输入 msiexec/regserver . 2.启用 Pri ...

  6. mac 上配置sublime text3插件

    1.安装MAC 版 sublime text 3 安装插件管理器 打开Sublime,按下Control + `(Mac)或者Ctrl + `(Windows),然后粘贴上下面的代码: import ...

  7. The Balance(母函数)

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  8. H264 编码详解

    H264 编码详解(收集转载) (1)       x264_param_default( x264_param_t *param ) 作用: 对编码器进行参数设定 cqm:量化表相关信息 csp: ...

  9. Jquery Mobile 记录

    使用的是C#语言,.Net+Jquery Mobile 框架开发 1.使用水平组切换操作 <fieldset id="Tfdset1" data-role="con ...

  10. EXT属性

    Extjs & Ext.Net 弹出整个浏览器对话框的方法 top.Ext.Msg.alert("值"); top.Ext.Msg.confirm("值" ...