Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
恢复到git add的最后一次更改_Git - Fatal编程技术网

恢复到git add的最后一次更改

恢复到git add的最后一次更改,git,Git,我正在处理git回购并发出命令 $ git add . 要保存当前修改 10分钟后,我不小心做了一些不好的更改,所以我想恢复到上次添加。地位 我搜索了,但发现只有方法可以重置为最新提交 我怎样才能回到十分钟前的状态。简短的回答是:你不能,git只提供返回到以前提交的方式(例如:你使用git提交提交的东西) 供将来使用:您可以运行git add.&&git commit-m WIP以“保存当前修改” 更详细的回答是:如果取回这个文件的前一个版本比保持你的心理健康更重要,你可以在悬垂的斑点列表中

我正在处理git回购并发出命令

$ git add .
要保存当前修改

10分钟后,我不小心做了一些不好的更改,所以我想恢复到上次添加。地位

我搜索了,但发现只有方法可以重置为最新提交


我怎样才能回到十分钟前的状态。

简短的回答是:你不能,git只提供返回到以前提交的方式(例如:你使用git提交提交的东西)

供将来使用:您可以运行
git add.&&git commit-m WIP
以“保存当前修改”


更详细的回答是:如果取回这个文件的前一个版本比保持你的心理健康更重要,你可以在悬垂的斑点列表中挖掘

  • 有一些方法可以粗略地检查“最近修改了哪些blob?”请参见中的一些指示


嘿,我知道我在什么地方有一些剧本:

下面的脚本将列出尚未打包到对象包中的无法访问的blob(最近的blob通常就是这种情况),并按创建日期对其进行排序(实际上:使用磁盘上文件的创建日期作为blob创建时间的估计值)

一些解释:

# git fsck --unreachable  ,  if you also use "--no-reflogs" this will search
# through commits which could be reached by the reflog but not by live branches
git fsck --no-reflogs --unreachable |\

# only keep lines mentioning "blobs" (files)
    grep blob |\

# keep the 3rd field of the output (hash of blob)
    cut -d' ' -f3 |\

# turn hashes into filenames, e.g :
#   aee01f414061ea9b0bdbbc1f66cec0c357f648fe ->
#   .git/objects/ae/e01f414061ea9b0bdbbc1f66cec0c357f648fe
# (this will be the path of this single blob)
    sed -e 's|^\(..\)\(.*\)|.git/objects/\1/\2|' |\

# give this to ls -lt (list by modification time),
# discard messages saying "file does not exist"
    xargs ls -l -t 2> /dev/null

我敢肯定你运气不好。尽早承诺,经常承诺。不进行提交的唯一原因是担心以后修改提交历史记录。不要害怕这样做。使用
git reset
来解除已提交文件的状态。使用
git fsck--lost-found
是一种快速恢复所有悬空blob的方法,但是它们的名称没有帮助,而且通常有很多要查看。
# git fsck --unreachable  ,  if you also use "--no-reflogs" this will search
# through commits which could be reached by the reflog but not by live branches
git fsck --no-reflogs --unreachable |\

# only keep lines mentioning "blobs" (files)
    grep blob |\

# keep the 3rd field of the output (hash of blob)
    cut -d' ' -f3 |\

# turn hashes into filenames, e.g :
#   aee01f414061ea9b0bdbbc1f66cec0c357f648fe ->
#   .git/objects/ae/e01f414061ea9b0bdbbc1f66cec0c357f648fe
# (this will be the path of this single blob)
    sed -e 's|^\(..\)\(.*\)|.git/objects/\1/\2|' |\

# give this to ls -lt (list by modification time),
# discard messages saying "file does not exist"
    xargs ls -l -t 2> /dev/null