1.问题
由于不小心的操作(想把本地仓库更新到GitHub的仓库里,一直没更新上去),导致了数据在gitkraken里删除了无法恢复。
软件里的Undo,以及右键的reset-soft、mixed、hard都没法恢复。
2.解决办法
1)由于gitkraken是GUI的软件,没有命令行可用。所以我们先安装Git,地址http://git-scm.com/downloads
2) 去本地仓库里的git目录,查看日志文件。比如:C:\Users\aaa\Desktop\文\ .git\logs\refs\heads\main
0000000000000000000000000000000000000000 734ae0b7392d1acdead04632712a9b3f8c758ff9 45411 <2747768001@qq.com> 1619249235 +0800 commit (initial): Initial commit
734ae0b7392d1acdead04632712a9b3f8c758ff9 2436ab0afcbac417416757c4f8672efd0d70d35e 45411 <2747768001@qq.com> 1619249279 +0800 commit: first
2436ab0afcbac417416757c4f8672efd0d70d35e 78b2118d27084a9807d5b9791c05b5f6235bcd62 45411 <2747768001@qq.com> 1619250319 +0800 commit (merge): Merge branch 'HEAD' into main
78b2118d27084a9807d5b9791c05b5f6235bcd62 811f10fc7232f40070cb18be84530b459fbda35b 45411 <2747768001@qq.com> 1622223512 +0800 commit: Update-21/5/29
811f10fc7232f40070cb18be84530b459fbda35b 78b2118d27084a9807d5b9791c05b5f6235bcd62 45411 <2747768001@qq.com> 1622224393 +0800 branch: Reset to 78b2118d27084a9807d5b9791c05b5f6235bcd62
3) 文件里找到自己消失不见的提交记录,比如我这里是:commit: Update-21/5/29,然后复制提交哈希值,左边是变化前右边是变化后,811f10fc7232f40070cb18be84530b459fbda35b
4)在Git GUI里打开本地的仓库,选择正确的目录。
5)然后在界面的操作栏:Repository-》Git Bash,打开命令行。
输入:git checkout 811f10fc7232f40070cb18be84530b459fbda35b;发现丢失的数据成功恢复了。
3.相关知识
1)使用命令:git log;查看日志的时候,发现没有commit: Update-21/5/29,需要去日志文件里查看哈希值。(编辑器是vim的话,按q键退出编辑)
2)Git Branch命令
git branch
-Display a list of the local branches in your Git repository.
git branch -a
-Display a list of both local branches and remote branches in your Git repository.
git branch -c
-Copy a Git branch.
git branch -d <branch-name>
-Delete a local Git branch. This command will not work if the branch you are attempting to delete has unmerged changes.
3) Git checkout命令
git checkout <branch-name>
-Switch to a different Git branch.
git checkout -b <branch-name>
-Create a new branch and switch to it.
git checkout -b <branch-name><remote-name>/<branch-name>
-Create a local branch from the remote Git branch and checkout that branch.
git checkout <commit hash>
-Checkout a previous Git commit.
git checkout <tag name>
-Checkout a Git tag in a detached HEAD state.
git checkout -b <branch-name><tag-name>
-Checkout a Git tag as a branch.
更多命令:
https://www.gitkraken.com/learn/git/commands
当在GitKraken中误删数据且软件内恢复失败时,可以通过安装Git并使用命令行来恢复。步骤包括查看本地仓库日志,找到消失的提交记录的哈希值,然后在Git Bash中执行`git checkout <哈希值>`。相关知识点涉及`git log`、`git branch`和`git checkout`等命令。
2844

被折叠的 条评论
为什么被折叠?



