你如何使用 Git、Eclipse 和 Egit 进行合并

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

How do you do merges using Git, Eclipse and Egit

eclipsegitversion-controlegit

提问by PaulHurleyuk

I, like many others, love Eclipseas my ide of choice, and because of the way I work (moving about, different places, different projects) want to use Gitfor CVS.

我和许多其他人一样,喜欢Eclipse作为我的首选 ide,并且由于我的工作方式(四处走动、不同的地方、不同的项目)希望将Git用于 CVS。

There is a plugin for Git in Eclipse, Egit, which is now an official Eclipse project, and currently at version 0.7.1. As I've just started using it I'm interested in how others are using it, and what work arounds they are using. Currently Egit doesn't have support for merges, so these have to be done outside of Eclipse and then the workspace refreshed.

Eclipse 中有一个 Git 插件Egit,它现在是一个官方的 Eclipse 项目,目前版本为 0.7.1。因为我刚刚开始使用它,所以我对其他人如何使用它以及他们正在使用的解决方法很感兴趣。目前 Egit 不支持合并,因此这些必须在 Eclipse 之外完成,然后刷新工作区。

So, How do you do this task ? (and any other tasks that Egit doesn't do right now)

那么,你如何完成这项任务?(以及 Egit 现在不执行的任何其他任务)

采纳答案by poke

When working with Eclipse, I only use egit to actually commit. Everything else I do simply via the command line. The command line in git (or any other VCS) is much more superior and the software was actually created with having the command line in mind, so it's just naturally that you can access really every single feature via the command line.

使用 Eclipse 时,我只使用 egit 来实际提交。我只需通过命令行完成其他所有操作。git(或任何其他 VCS)中的命令行要优越得多,而且该软件实际上是在考虑到命令行的情况下创建的,因此很自然地,您可以通过命令行访问每个功能。

Everything else only uses the command line in the background and tries to emulate a different interface, native to the host application (here: Eclipse). But by doing that you can never reach the same power as by using the original tools.

其他一切都只在后台使用命令行,并尝试模拟主机应用程序本机的不同界面(此处:Eclipse)。但是这样做,您永远无法获得与使用原始工具相同的力量。

However I think when egit develops more, it might be a good way to work with git; similar to how the subversion plugin for Eclipse works well with most functions. But in my situation, I don't use Eclipse for everything and using the command line is then a lot simpler than trying to get used to multiple different plugins andthe command line.

但是我认为当 egit 发展得更多时,它可能是使用 git 的好方法;类似于 Eclipse 的 subversion 插件如何很好地处理大多数功能。但是在我的情况下,我不会将 Eclipse 用于所有事情,并且使用命令行比尝试习惯多个不同的插件命令行要简单得多。

回答by MrCeeJ

Just for reference, EGIT does now support merges and uses the powerful diff interface within eclipse.

仅供参考,EGIT 现在支持合并并在 eclipse 中使用强大的 diff 接口。

Once you have fetched the code and run a merge, if there are any conflicts they are highlighted in the project explorer with a red !, you can then right click on them and go to Team > Merge Tool, which is un-ghosted for conflicted files.

获取代码并运行合并后,如果存在任何冲突,它们会在项目资源管理器中以红色突出显示!,然后您可以右键单击它们并转到“团队”>“合并工具”,该工具不会对冲突进行重影文件。

Once you have selected the code you wish to use (Either the workspace version with diff annotations in it or the HEAD version that caused the conflict) the diff window will open.

一旦你选择了你想要使用的代码(无论是带有差异注释的工作区版本还是导致冲突的 HEAD 版本),差异窗口将打开。

This shows your local code on the left and the conflicting code on the right, you can use the 'next difference' button to jump through all the conflicts, and the 'copy change from right to left' button to accept the remote version, or simply edit your local version in place.

这在左边显示您的本地代码,在右边显示冲突代码,您可以使用“下一个差异”按钮跳过所有冲突,并使用“从右向左复制更改”按钮接受远程版本,或只需在适当的位置编辑您的本地版本。

Once you are happy with the changes save your file and add it, then commit the results and you should be done.

一旦您对更改感到满意,请保存您的文件并添加它,然后提交结果,您应该就完成了。

Please note I am in no way a master of git good practice, so please feel free to correct me if these are not the best operations to use, but it was an answer to the question "How do I do merges in eclipse with egit".

请注意,我绝不是 git 良好实践的大师,所以如果这些不是最好的操作,请随时纠正我,但这是对“我如何在 eclipse 中使用 egit 合并”这个问题的回答.

回答by noob

One way to work out with Egit merge conflict is to take backup of your file, delete it from eclipse, put it back from backup, Add to index and commit.

解决 Egit 合并冲突的一种方法是备份您的文件,从 eclipse 中删除它,将其从备份中放回,添加到索引并提交。

This should be done only if you can't resolve the conflict with normal Add to Index->Commit method.

仅当您无法使用普通的 Add to Index->​​Commit 方法解决冲突时,才应该这样做。

PS: I assume you've already resolved the conflict manually or by using Egit merge tool, but just can't remove the conflict marker on the file.

PS:我假设您已经手动或使用 Egit 合并工具解决了冲突,但无法删除文件上的冲突标记。