有没有办法从git重置中恢复未提交的更改到工作目录-hard HEAD?
当前回答
如果我丢失了一些零钱,我通常会这么做。
git reflog
git checkout <commit id> // now you are in where you want but you cannot push from detached branch to master
manually copy and paste changes from detached branch to master or working branch
git reset --hard HEAD // if needed
git add ... > git commit ... > git push ...
要将指针移回你之前的提交,但保持你在最近一次提交中所做的更改,checkout git reset -soft dadada
其他回答
根据定义,git reset -hard会丢弃未提交的更改,git无法恢复它们(你的备份系统可能会有帮助,但不是git)。
实际上,很少有git重置的情况——困难是个好主意。在大多数情况下,有一个更安全的命令来做同样的事情:
If you want to throw away your uncommitted changes, then use git stash. It will keep a backup of these changes, which will expire after some time if you run git gc. If you're 99.9% sure you'll never need these changes back, then git stash is still your friend for the 0.1% case. If you're 100% sure, then git stash is still your friend because these 100% have a measurement error ;-). If you want to move your HEAD and the tip of the current branch in history, then git reset --keep is your friend. It will do the same thing as git reset --hard, but will not discard your local changes. If you want to do both, then git stash && git reset --keep is your friend.
教你的手指不要使用git重置——很难,总有一天会有回报的。
我刚刚做了git重置-困难和丢失了所有未提交的更改。幸运的是,我使用了一个编辑器(IntelliJ),我能够从本地历史记录中恢复更改。Eclipse应该允许您做同样的事情。
当我在做一个本地项目时,我想把它移动到GitHub上,然后创建一个新的存储库。当我试图用.gitignore将所有这些文件添加到新的存储库中时,我不小心添加了一个错误的文件,然后试图清除它。
我运行了git reset -hard origin/master
然后我所有的本地文件都被删除了,因为回购是空的。我以为一切都消失了。
这招对我很管用:
git reflog show
git reset HEAD@{1}
git push
如果我丢失了一些零钱,我通常会这么做。
git reflog
git checkout <commit id> // now you are in where you want but you cannot push from detached branch to master
manually copy and paste changes from detached branch to master or working branch
git reset --hard HEAD // if needed
git add ... > git commit ... > git push ...
要将指针移回你之前的提交,但保持你在最近一次提交中所做的更改,checkout git reset -soft dadada
嗯,据我所知,最好的解决方案是使用IDE特性。
选择丢失文件的存储库,并右键单击它 在菜单>中查找本地历史显示历史 现在检查版本版本,你所有的文件都存在>,选择它,然后点击恢复。 这就是最可能的情况。
注意:上述解决方案适用于在任何IDE(如intelliJ)中进行更改或导入存储库。
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别