Eclipse git checkout(又名,还原)

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

Eclipse git checkout (aka, revert)

eclipsegiteclipse-pluginegit

提问by Steve Kuo

Is it possible to do the equivalent of git checkoutfrom within Eclipse using the EGit plugin?

是否可以git checkout使用 EGit 插件在 Eclipse 中执行等效操作?

I have a file that's been modified. I want to discards the changes and revert the file back to what's in the source repository. In Subversion this is called revert. In git the equivalent is checkout.

我有一个已被修改的文件。我想放弃更改并将文件恢复到源存储库中的内容。在 Subversion 中,这称为还原。在 git 中,等价物是结帐。

I can't find any menu item under Team that looks like checkout or revert. I'm using EGit 0.6.0.

我在 Team 下找不到任何类似于 checkout 或 revert 的菜单项。我正在使用 EGit 0.6.0。

回答by Sergii Rudchenko

This can be done via the context menu "Replace with/File in Git index" on the file in package view.

这可以通过包视图中文件的上下文菜单“在 Git 索引中替换为/文件”来完成。

回答by simon

You can achieve this by doing a (hard) reset. On the project's context menu, select Team > Reset to..., choose "HEAD" and "Hard" as reset type.

您可以通过执行(硬)重置来实现此目的。在项目的上下文菜单上,选择 Team > Reset to...,选择“HEAD”和“Hard”作为重置类型。

Please note that doing this you will lose the changes of ALL files. To revert just a single file see this answer.

请注意,这样做您将丢失所有文件的更改。要仅还原单个文件,请参阅此答案

回答by ekeren

in Eclipse Version: 3.7.0

在 Eclipse 版本中:3.7.0

in "Team Synchronizing perspective" --> right click on file/folder in synchronize view --> overwrite

在“团队同步视角”中 --> 在同步视图中右键单击文件/文件夹 --> 覆盖

回答by robinst

Another possibility is using the Git Staging view:

另一种可能性是使用Git Staging 视图

  • Open Git Stagingview by pressing Ctrl+3 or Command+3 and typing
    staging
  • In case the view does not already show your repository, click on the project or file
  • You should now see the files you modified in the Unstaged Changessection
  • Double-click on the unstaged file
  • You now see a compare view with your version on the left and the version before the changes on the right
  • 按 Ctrl+3 或 Command+3 并键入打开Git 暂存视图
    staging
  • 如果视图尚未显示您的存储库,请单击项目或文件
  • 您现在应该在Unstaged Changes部分看到您修改的文件
  • 双击未暂存的文件
  • 您现在可以在左侧看到与您的版本和右侧更改之前的版本的比较视图

Now, to undo only some of the changes in the file, do the following:

现在,要仅撤消文件中的部分更改,请执行以下操作:

  • In the compare view, select one of your changed lines
  • Select the Copy Current Change From Right to Lefttoolbar item
  • 在比较视图中,选择您更改的行之一
  • 选择从右到左复制当前更改工具栏项

This will make the left side correspond to the right side for this change. Save the file to finish the undo.

这将使左侧对应于此更改的右侧。保存文件以完成撤消。

To undo all of your changes:

要撤消所有更改:

  • In the staging view, right click on the unstaged file
  • Select Replace With File in Git Index
  • 在暂存视图中,右键单击未暂存的文件
  • 在 Git 索引中选择替换为文件

You can also select more than one unstaged file and then right click.

您也可以选择多个未暂存的文件,然后右键单击。

回答by T A

Revert a single file by going to Window > Show View > Other > Git Staging > Unstaged Changes

通过转到Window > Show View > Other > Git Staging > Unstaged Changes来恢复单个文件

Select the file(s) you wish to revert. Right click and choose Replace with HEAD revision

选择要还原的文件。右键单击并选择用 HEAD 修订版替换

Note that this step can't be undone.

请注意,此步骤无法撤消。

(I am using Eclipse Version: 3.7.2 Egit version 2.3.1.201302201838-r)

(我使用的是 Eclipse 版本:3.7.2 Egit 版本 2.3.1.201302201838-r)

回答by user3812819

For reverting, you can right click on the file/directory that you want, then select Replace With-> HEAD version

对于恢复,您可以右键单击所需的文件/目录,然后选择替换为-> HEAD 版本

回答by Geddon

Open Team Synchronizing. Find the file and right click --> Overwrite.

打开团队同步。找到文件并右键单击--> 覆盖。

UPDATE

更新

In Eclipse Luna (4.4.2) Open Team Synchronizing. Find the file and right click --> "Revert..."

在 Eclipse Luna (4.4.2) 中打开团队同步。找到文件并右键单击-->“还原...”

回答by robinr

The functionality is actually in there, but it may be non-obvious:

功能实际上就在那里,但它可能不明显:

  • Make sure quickdiff is enabled with a git revision and the quickdiff baseline is HEAD (this is the default).
  • Open the file you want to revert.
  • Select everything (Ctrl-A)
  • Right-Click in the quickdiff bar
  • Select "Revert selection"
  • Save
  • 确保使用 git 修订版启用了 quickdiff,并且 quickdiff 基线是 HEAD(这是默认值)。
  • 打开要还原的文件。
  • 全选 (Ctrl-A)
  • 在快速差异栏中右键单击
  • 选择“还原选择”
  • 节省

btw, revert in git lingo means create a new commit to revert an earlier commit.

顺便说一句,在 git 术语中恢复意味着创建一个新的提交来恢复之前的提交。

回答by adhg

To revertyour entire file to repository's data:

要将整个文件恢复为存储库的数据:

Click on the folder you wish to do the revision and then go to the GitStaging enter image description here

单击要进行修订的文件夹,然后转到 GitStaging 在此处输入图片说明