C# 在 Visual Studio 2012 中恢复到 Git 中的先前提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17258289/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:58:49  来源:igfitidea点击:

Reverting to a previous commit in Git for visual studio 2012

c#.netgitvisual-studio

提问by Win Coder

I am really new to git and source control.

我对 git 和源代码控制真的很陌生。

I am using visual studio tools for git with vs2012.

我正在将 Visual Studio 工具用于 git 和 vs2012。

I am on some commit and want to go back to some previous commit but i cannot seem to do it how. When i go to the commit details the revert button seems to have been grayed out.

我正在进行一些提交并想回到以前的某个提交,但我似乎无法做到这一点。当我转到提交详细信息时,还原按钮似乎已变灰。

I have stuck on this problem for the last 2 hours. I have researched the internet but to no use. Please can somebody tell me how to revert to a previous commit.

在过去的 2 个小时里,我一直在解决这个问题。我已经研究了互联网,但没有用。请有人告诉我如何恢复到以前的提交。

Thanks.

谢谢。

采纳答案by Win Coder

Well to those newbies who have the same problem, the best way not to waste 3 hours of your life is simply not to use visual studio tool for GIT. At least not in its current form.(23 Jun 2013)

那么对于那些有同样问题的新手来说,不浪费生命 3 小时的最好方法就是不要使用 Visual Studio 工具进行 GIT。至少不是目前的形式。(2013 年 6 月 23 日)

After wasting much time i found out from an obscure link that the vs extension only supports a few of the GIT function with reset not being one of them.

在浪费了很多时间之后,我从一个晦涩的链接中发现 vs 扩展只支持少数 GIT 函数,而 reset 不是其中之一。

回答by Oved D

You don't want to do a revert - revert just takes a commit and undoes it.

您不想执行还原 - 还原只需提交并撤消它。

If you want to go back to a previous commit - there are two options:

如果你想回到之前的提交 - 有两种选择:

If you want to permanently go back, do a git hard reset, which rolls back the code to a specified commit. You can do this via:

如果您想永久返回,请执行 git hard reset,将代码回滚到指定的提交。您可以通过以下方式执行此操作:

git reset --hard {commit number}

If you want to temporarily go back, you can create a branch from that commit.which will essentially keep you current path in the code history, and create another path from the point in history where that code was committed.

如果您想暂时返回,可以从该提交创建一个分支。这基本上将使您在代码历史记录中保持当前路径,并从提交该代码的历史记录点创建另一条路径。

回答by nest

In Team Explorer -> Branchesthen select Actions -> Open command promptand use the git commands either:

Team Explorer -> Branches随后选择Actions -> Open command prompt,要么使用Git命令:

  • git checkout your commit id
  • git reset your commit id
  • 结帐 your commit id
  • 重置 your commit id

check this out to understand the difference What's the difference between "git reset" and "git checkout"?

检查这个以了解区别“git reset”和“git checkout”之间有什么区别?

I think you'll also need to have git extension installed in Visual Studio, I have it, but not sure it's required to do that.

我认为您还需要在 Visual Studio 中安装 git 扩展,我有,但不确定是否需要这样做。

enter image description here

在此处输入图片说明

回答by Runar Jordahl

Visual Studio 2015 Update 2adds support for GIT "Reset", which is what you probably want to do:

Visual Studio 2015 Update 2添加了对 GIT“重置”的支持,这可能是您想要做的:

  • open history
  • right click the commit you want to revert to
  • reset -> reset and delete changes
  • 打开历史
  • 右键单击要还原的提交
  • 重置 -> 重置和删除更改

GIT Reset in Visual Studio 2015 Update 2

Visual Studio 2015 Update 2 中的 GIT 重置