Intellij git 还原提交

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

Intellij git revert a commit

gitintellij-idea

提问by dimzak

I was using Eclipseand Egitfor a long time and decided to try Intellij.
So far so good, except one thing...
I can't find an easy way to revert an old commit from my repo!!!

我使用EclipseEgit很长一段时间,并决定尝试Intellij
到目前为止一切顺利,除了一件事......
我找不到一种简单的方法来从我的回购中恢复旧的提交!!!

In Eclipse the standard process was: Go to Git Workspace -> Click Show History(Right Click Project) -> RIght-Click on the commit I want to revert and press Revert Commit.

在 Eclipse 中,标准流程是: Go to Git Workspace -> Click Show History(Right Click Project) -> RIght-Click on the commit I want to revert and press Revert Commit.

In Intellij I can't find anything equivalent. Tried VCS -> Show Changes Viewbut there I can only cherry picka commit. I also played with the revert option under VCS -> gitbut got confused by the changelistthing(That may hide the answer, but I don't understand how it works).

在 Intellij 中,我找不到任何等效的东西。尝试过,VCS -> Show Changes View但我只能cherry pick提交。我也玩过下面的还原选项,VCS -> git但被这个changelist东西弄糊涂了(这可能隐藏了答案,但我不明白它是如何工作的)。

I can still revert the commit by issuing git revert <sha>from terminal but that's what I was trying to avoid in the first place by using git from Intellij and not pure terminal.

我仍然可以通过git revert <sha>从终端发出来恢复提交,但这就是我首先试图通过使用 Intellij 中的 git 而不是纯终端来避免的。

Is there a way to do easily the revert in Intellij?

有没有办法在 Intellij 中轻松进行恢复?

回答by c0stra

If you go to Changelist -> Log, and there select the commit, you've got a change detail in the right panel. There you can select all and click a button (or right click -> revert selected changes).

如果您转到 Changelist -> Log,然后选择提交,您将在右侧面板中看到更改详细信息。在那里您可以全选并单击一个按钮(或右键单击 -> 还原选定的更改)。

回答by Andreas Wederbrand

I know of only one way and it's not as good as doing it command line.

我只知道一种方法,它不如在命令行中执行。

First create a reverse patch. Go into the log, choose any commit and select create patch, check reverse patchand save it anywhere.

首先创建一个反向补丁。进入日志,选择任何提交并选择create patch,检查reverse patch并保存在任何地方。

Then go into VCS menu and select apply patchand choose the file you just saved.

然后进入 VCS 菜单并选择apply patch并选择您刚刚保存的文件。

Commit those changes.

提交这些更改。

Still, I would go with doing it command line. Gives a proper automatic commit message as well.

尽管如此,我还是会用命令行来做。还提供适当的自动提交消息。

回答by lostiniceland

  1. Selectthe commit you like to revert in the history-log.
  2. From the context-menu select Create Patch...
  3. Select Reverse patchcheckbox
  4. Applythe created patch
  1. history-log 中选择您想恢复的提交。
  2. 从上下文菜单中选择创建补丁...
  3. 选择反向补丁复选框
  4. 应用创建的补丁

回答by domaru

I've been looking for that option in Idea 2016.2 and it seems it is no longer there ("revert selected changes"). Instead I was able to do "Reset Current Branch to Here" with "Mized" option, pointing to the latest correct commit. Then I was able to just do the commit again.

我一直在 Idea 2016.2 中寻找该选项,但它似乎不再存在(“还原选定的更改”)。相反,我能够使用“Mized”选项执行“将当前分支重置到此处”,指向最新的正确提交。然后我就可以再次提交。