git reset --soft并返回到最新的提交 [英] git reset --soft and going back to the latest commit

查看:200
本文介绍了git reset --soft并返回到最新的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我只是做了一个git --reset soft来回到之前的提交。现在如果我想回到我之前的最新提交,该怎么办?即:最新的提交?我试着做git log,但是那里列出的提交没有最新的提交。

git reset 是一个错误的工具,如果你只想回去查看一个旧的提交,因为在很多模式下,它实际上是通过删除提交来改变历史,正如你发现的那样。 p>

如果您想临时在工作树中获得旧提交,请使用 git checkout 。在这种情况下, git checkout HEAD ^ 会带你回到一个提交。 git checkout HEAD〜3 会带你回到三个提交,依此类推。或者你可以给它从 git log



的散列。然后你可以通过执行 git checkout master (用任何分支的名称替换 master )。


So I just did a git --reset soft to go back to a previous commit. Now what if I want to go back to the latest commit that I was at before? i.e: the latest commit? I tried doing git log, but the commit listed there didn't have the latest commit.

解决方案

git reset is the wrong tool to use if you just want to go back and look at an old commit, since in many modes it actually alters the history by removing commits, as you've discovered.

If you want to temporarily get an old commit back in your working tree, just use git checkout. In this case, git checkout HEAD^ will take you back one commit. git checkout HEAD~3 will take you back three commits, and so on. Or you can give it the hash from git log.

You can then return to the latest commit by doing git checkout master (replacing master with the name of any branch).

这篇关于git reset --soft并返回到最新的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆