Git-删除文件后找回

Posted lxl616

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Git-删除文件后找回相关的知识,希望对你有一定的参考价值。

#前提:删除前,文件存在是的状态提交到了本地库
#操作: git reset --hard 指针位置
    删除操作已近提交到本地库:指针指向历史记录
    



[email protected]004 MINGW64 /c/LXL Working-Place/Git-Work $ cd Test/ [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ vim aaa.txt [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git add aaa.txt warning: LF will be replaced by CRLF in aaa.txt. The file will have its original line endings in your working directory [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git commit -m "new txt" aaa.txt warning: LF will be replaced by CRLF in aaa.txt. The file will have its original line endings in your working directory [master 5723a86] new txt 1 file changed, 2 insertions(+) create mode 100644 aaa.txt [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git status On branch master nothing to commit, working tree clean [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ rm aaa.txt [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ ll total 1 -rw-r--r-- 1 linxianli 1049089 125 四月 25 16:32 good.txt [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ 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: aaa.txt no changes added to commit (use "git add" and/or "git commit -a") [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git refloog git: refloog is not a git command. See git --help. The most similar command is reflog [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git reflog 5723a86 (HEAD -> master) [email protected]{0}: commit: new txt c37331e [email protected]{1}: reset: moving to HEAD c37331e [email protected]{2}: reset: moving to c37331e c37331e [email protected]{3}: reset: moving to c37331e dbc8b46 [email protected]{4}: reset: moving to HEAD^ c37331e [email protected]{5}: reset: moving to c37331e ea4d3ce [email protected]{6}: commit: 10 c37331e [email protected]{7}: commit: 9 dbc8b46 [email protected]{8}: commit: 8 719c75a [email protected]{9}: commit: 7 ca821b6 [email protected]{10}: commit: 6 060a421 [email protected]{11}: commit: 5 8d1f64d [email protected]{12}: commit: 4 de0c64e [email protected]{13}: commit: 3 9718c85 [email protected]{14}: commit: second commit,modify 14e7a11 [email protected]{15}: commit (initial): first commit [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git reset --hard ^C [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ git reset --hard 5723a86 HEAD is now at 5723a86 new txt [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $ ll total 2 -rw-r--r-- 1 linxianli 1049089 12 四月 26 11:42 aaa.txt -rw-r--r-- 1 linxianli 1049089 125 四月 25 16:32 good.txt [email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master) $

 

 

比较文件差异:

    git diff [文件名]

      将工作区的文件和暂存区的文件进行比较

      git diff [本地库中的历史版本] [文件名]

       将工作区中的文件和本地库的历史记录进行比较

     git diff

       不带文件名就是比较多个文件

 

[email protected]004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master)
$ vim good.txt

[email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master)
$ git diff
diff --git a/good.txt b/good.txt
index 5e87980..69eb60a 100644
--- a/good.txt
+++ b/good.txt
@@ -9,3 +9,4 @@ ijfksdahkfh
 kjlhkjhkjs
 dsaklfhkjla
 sdfsfsfsdfdsf
+ABC

[email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master)
$ git diff HEAD
diff --git a/aaa.txt b/aaa.txt
index 051eb5a..f2be101 100644
--- a/aaa.txt
+++ b/aaa.txt
@@ -1,2 +1,3 @@
 aa a
 bbbb
+vvvvv
diff --git a/good.txt b/good.txt
index 5e87980..69eb60a 100644
--- a/good.txt
+++ b/good.txt
@@ -9,3 +9,4 @@ ijfksdahkfh
 kjlhkjhkjs
 dsaklfhkjla
 sdfsfsfsdfdsf
+ABC

[email protected]-QS-004 MINGW64 /c/LXL Working-Place/Git-Work/Test (master)
$

 

以上是关于Git-删除文件后找回的主要内容,如果未能解决你的问题,请参考以下文章

git找回本地误删除的文件

git删除之后怎么恢复

Git未提交代码,切换分支后,代码丢失,怎么找回

修改后的代码只进行了git add操作不小心给他恢复了怎么找回来

git 找回 git reset --hard HEAD 后的代码

如何删除 Git 仓库中的历史提交记录