我正在做一个git回购并发出命令
$ git add .为了保存当前的修改,
10分钟后,我意外地做了一些坏的更改,所以我想恢复到最后的添加。状态。
我搜索了,但发现只有方法可以重置为最新提交。
我怎么能回到十分钟前的状态。
发布于 2018-10-30 16:27:08
简短的回答是:您不能,git只提供返回以前提交的方法(例如:使用git commit注册的内容)
将来使用:您可以运行git add . && git commit -m WIP来“保存当前的修改”
更长的答案是:如果回到这个文件的前一个版本比保持你的精神健康更重要的话,你可能会深入到悬空的斑点列表中。
嘿,我知道我在某个地方有个剧本:
下面的脚本将列出尚未打包到对象包中的不可访问的blob (最近的blob通常是这种情况),并按创建日期对它们进行排序(实际上:使用磁盘上文件的创建日期来估计blob创建的时间)
#!/bin/sh
git fsck --no-reflogs --unreachable |\
grep blob |\
cut -d' ' -f3 |\
sed -e 's|^\(..\)\(.*\)|.git/objects/\1/\2|' |\
xargs ls -l -t 2> /dev/null一些解释:
# 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 "blob" (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/nullhttps://stackoverflow.com/questions/53068697
复制相似问题