git 回到 Github Desktop 中的先前提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34790794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Going back to a previous commit in Github Desktop
提问by morishuz
I am trying to use GitHub Desktop (i.e. the GUI application - NOT command line) to go back to a previous commit (on the same branch). Something that I would have thought is a core feature, since it's the primary reason for using source control in the first place.
我正在尝试使用 GitHub Desktop(即 GUI 应用程序 - 而不是命令行)返回到先前的提交(在同一分支上)。我本以为是核心功能,因为它是首先使用源代码管理的主要原因。
I can see that it's possible to revert a commit, but this is not really what I want as it creates a new commit. I would just simply like to go back with the option of going forward again, in the same way that I can just hop to a different branch.
我可以看到可以还原提交,但这并不是我真正想要的,因为它会创建一个新的提交。我只是想回去选择再次前进,就像我可以跳到不同的分支一样。
Is this possible or is it a limitation of github desktop and I need to use the cmd line for that?
这是可能的还是 github 桌面的限制,我需要为此使用 cmd 行?
回答by SevenEleven
In general, you can go back to a commit in your history with git reset
.
通常,您可以使用git reset
.
This is not possible with GitHub Desktop. GitHub Desktop is more of a tool to synchronize your repositories and not a full featured GUI client.
But that doesn't mean you have to use the command line, since there are alternatives. You can find a list here. To mention a few (that support git reset
):
这在 GitHub Desktop 中是不可能的。GitHub Desktop 更像是一个同步存储库的工具,而不是一个功能齐全的 GUI 客户端。
但这并不意味着您必须使用命令行,因为还有其他选择。您可以在此处找到列表。举几个(支持git reset
):
- TortoiseGit(Windows)
- SourceTree(Mac, Windows)
- TortoiseGit(Windows)
- SourceTree(Mac, Windows)
Here is how you do it on command line. Most clients provide this in their UI using the same vocabulary (usually, you are able to select a commit and reset to itvia context menu).
这是您在命令行上执行此操作的方法。大多数客户端使用相同的词汇在其 UI 中提供此功能(通常,您可以选择提交并通过上下文菜单重置它)。
You will go back to the previous commit with
您将返回到上一次提交
git reset HEAD^
or some more commits (for example 3) by
或更多提交(例如 3)
git reset HEAD^3
or to a specific commit by
或特定提交
git reset f7823ab
Have in mind that, by default, the option --mixed
is passed to git reset
. So, all changes made, since that commit you reset to, will still be there.
请记住,默认情况下,该选项--mixed
会传递给git reset
. 因此,自从您重置为该提交以来所做的所有更改仍将存在。
To get the original state of the commit that you want to 'revert', you have to pass --hard
. For example:
要获得要“还原”的提交的原始状态,您必须通过--hard
. 例如:
git reset f7823ab --hard
回答by Alex Albracht
(EDIT: Github Desktop lacks the requested command; below are instructions for a somewhat different action, that you may find useful.)
(编辑:Github Desktop 缺少请求的命令;以下是一些不同操作的说明,您可能会觉得有用。)
1. Click History.
2. In the commit history list, click the commit you'd like to revert.
3. Right-click the commit and click Revert This Commit.
Documentation from GitHub
来自GitHub 的文档