git Eclipse 和 EGit:如何在提交到 *local* 存储库之前轻松查看对所有修改过的文件的更改

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

Eclipse and EGit: How to easily review changes to ALL modified files before committing to *local* repository

eclipsegitegit

提问by Lambart

I'm using Eclipse Indigo SR2 with the (built-in) EGit plugin v.1.3.0.201202151440-r and haven't been able to find any way to easily review all my changes before making a commit.

我正在使用带有(内置)EGit 插件 v.1.3.0.201202151440-r 的 Eclipse Indigo SR2,并且在提交之前无法找到任何方法来轻松查看我的所有更改。

I used Eclipse with SVN for years, and this was always very easy to do. I would typically right-click on my project, select Team->Synchronize, double-click on the first changed file (in the Team Sync perspective), then hit Ctrl-.repeatedly to review all changes in one file, and then proceed to the next file, as I wrote a summary of my changes for the commit message.

我将 Eclipse 与 SVN 一起使用多年,这总是很容易做到。我通常会右键单击我的项目,选择Team->Synchronize,双击第一个更改的文件(在 Team Sync 透视图中),然后点击Ctrl-.重复查看一个文件中的所有更改,然后继续下一个文件,因为我写了我对提交消息所做更改的摘要。

But of course, git is very different from Subversion, and so my workflow must change. With EGit, "Team Sync" only appears to be useful for reviewing changes between my local files and the remote repository (i.e. before a push to the remote). I need a way to review changes since my last commit to my localrepository. I generally don't even care to (re)review changes before a push to remote (and if I did, I'd prefer a simple equivalent of git logto see what commits I'm about to push).

但是当然,git 与 Subversion 有很大不同,所以我的工作流程必须改变。使用 EGit,“团队同步”似乎只对查看我的本地文件和远程存储库之间的更改有用(即在推送到远程之前)。我需要一种方法来检查自上次提交到本地存储库以来的更改。我通常甚至不关心在推送到远程之前(重新)更改(如果我这样做了,我更喜欢一个简单的等价物git log来查看我将要推送的提交)。

If I right-click on my project and select Team->Commit, I am presented with a window that does almosteverything I need to do (select files to stage, commit, write a commit message, amend a previous commit, etc.). What it doesn'tallow me to do is quickly and easily review all my changes in a compare editor. I can't believe this capability doesn't exist! It seems I am required to double-click on each individual file, review the changes, close the compare editor, and double-click on the next file. That's ridiculous!

如果我右键单击我的项目并选择Team->Commit,我会看到一个窗口,该窗口几乎可以完成我需要做的所有事情(选择要暂存的文件、提交、编写提交消息、修改以前的提交等)。什么是容许我这样做快速,轻松地为所有我在比较编辑器中修改。我不敢相信这种能力不存在!似乎我需要双击每个单独的文件,查看更改,关闭比较编辑器,然后双击下一个文件。这是荒谬的!

TL/DR - I am looking for a simple GUI equivalent (in Eclipse) to do what I am easily able to do from the command line using git vimdiff(where vimdiff is a git alias that uses vimdiff as the "difftool" to cycle through all modified files) followed by git commit(with perhaps a git addor two in between).

TL/DR - 我正在寻找一个简单的 GUI 等价物(在 Eclipse 中)来做我很容易从命令行使用的东西git vimdiff(其中 vimdiff 是一个 git 别名,它使用 vimdiff 作为“difftool”来循环浏览所有修改文件),然后是git commit(中间可能有一git add两个)。

If no one has a good solution, I am curious about how others handle their commit workflow with EGit. I've been getting along fine committing from the command line (not that Eclipse is happy about that) but I can't believe that EGit is as near-useless as it seems to me. Perhaps my google-fu is not as strong as it once was?

如果没有人有好的解决方案,我很好奇其他人如何使用 EGit 处理他们的提交工作流程。我一直在通过命令行进行良好的提交(并不是 Eclipse 对此感到高兴),但我无法相信 EGit 像在我看来一样近乎无用。也许我的 google-fu 不像以前那么强大了?

采纳答案by Deepak Azad

Are you aware of the 'Git Staging' view. It keeps track of all the files that have changed and you can review the changes any time. (This can be a bit better than using the commit dialog)

您是否了解“Git Staging”视图。它跟踪所有已更改的文件,您可以随时查看更改。(这可能比使用提交对话框好一点)

An alternative is to commit all changes without reviewing, and then use the history view to compare two commits (Simply select the last top most commits, right click and select 'Compare with each other'). This way you do not have to keep double clicking individual files. If you need to change something you can always 'Amend' the last commit. (I usually follow this approach)

另一种方法是不就提交所有更改,然后使用历史视图来比较两次提交(只需选择最后一个最高的提交,右键单击并选择“相互比较”)。这样您就不必一直双击单个文件。如果您需要更改某些内容,您可以随时“修改”最后一次提交。(我通常遵循这种方法)

回答by Thomas Ferris Nicolaisen

Says herethat you can see the diffs between the working tree and any given reference. Perhaps you should try out the latest version (Juno) of Eclipse/EGit and see if it's gotten any better?

在这里,你可以看到工作树和任何给定的参考值之间的差异列表。也许您应该尝试最新版本的 Eclipse/EGit (Juno),看看它是否变得更好?

Update: I've tried this out in the latest Eclipse, and as far as I can see it works fine. Here's how:

更新:我已经在最新的 Eclipse 中尝试过这个,据我所知它工作正常。就是这样:

In the moment of writing this, Eclipse Juno 4.2 is the version you should go for. On the download page, you can pick between several packages according to your needs. The 'Eclipse IDE for Java Developers' comes bundled with EGit, but you can also install EGit into any distribution using the Eclipse Marketplace (under the Help menu).

在撰写本文时,Eclipse Juno 4.2 是您应该选择的版本。在下载页面上,您可以根据需要在多个软件包之间进行选择。'Eclipse IDE for Java Developers' 与 EGit 捆绑在一起,但您也可以使用 Eclipse Marketplace(在帮助菜单下)将 EGit 安装到任何发行版中。

  • Once you've imported your project into Eclipse, make sure the project is "shared":
  • 将项目导入 Eclipse 后,请确保该项目是“共享的”:

Right-click project -> Team -> Share Project.. -> Git

右键单击项目 -> 团队 -> 共享项目.. -> Git

Now do the following:

现在执行以下操作:

  • Switch to the Team Synchronizing Perspective.
  • Click the little synchronize button in the Synchronize View.
  • Choose Git
  • Pick a suitable branch to sync against, like refs/remotes/origin/master
  • Make sure to check the "Include local uncommitted changes in comparison" box
  • Click Finish
  • 切换到团队同步视角。
  • 单击同步视图中的小同步按钮。
  • 选择 Git
  • 选择一个合适的分支进行同步,比如 refs/remotes/origin/master
  • 确保选中“在比较中包含本地未提交的更改”框
  • 单击完成

Now, change some files and watch them appear in the Synchronize View. Double-click the changed files to see the diff (like in the screenshot below).

现在,更改一些文件并观察它们出现在同步视图中。双击更改的文件以查看差异(如下面的屏幕截图所示)。

Screenshot of Eclipse Juno - EGit Synchronize View

Eclipse Juno - EGit 同步视图的屏幕截图

回答by Kt Mack

I am writing this as of Eclipse Oxygen, but it should apply to other versions as well.

我是从 Eclipse Oxygen 开始写这篇文章的,但它也应该适用于其他版本。

  1. Option 1 with team synchronizing view: right click the project > Compare with > Commit.You can choose your latest commit here, even if you haven't pushed it to repository.
  2. Option 2 with diff view: If you want to see the "diff" version without committing, you can achieve this by right clicking your project > team > stashes > Stash Changes > check Include untracked files.This will save all of your changes to a stash. Then you will right click project > team > stashes > select stash you saved.You click the green arrow at the top right to re-apply all of your changes you stashed back to your code. In the same stash window, you will see a "Diff" tab at the bottom right. Clicking on the diff tab will show your changes in the red/green highlighted diff style. I wish there was a way to generate a diff view without stashing, but this is the only work-around I have found.
  1. 带有团队同步视图的选项 1:右键单击项目 > 比较 > 提交。您可以在此处选择最新的提交,即使您尚未将其推送到存储库。
  2. 带有差异视图的选项 2:如果您想在不提交的情况下查看“差异”版本,您可以通过右键单击您的项目 > 团队 > 藏匿 > 藏匿更改 > 选中包括未跟踪的文件来实现此目的这会将您的所有更改保存到存储中。然后,您将右键单击项目 > 团队 > 藏匿处 > 选择您保存的藏匿处。您单击右上角的绿色箭头,将您隐藏的所有更改重新应用到代码中。在同一个存储窗口中,您将在右下角看到一个“差异”选项卡。单击差异选项卡将以红色/绿色突出显示的差异样式显示您的更改。我希望有一种方法可以在不隐藏的情况下生成差异视图,但这是我找到的唯一解决方法。