简体   繁体   English

如何在Eclipse中合并代码

[英]How to merge code in Eclipse

How do I dot the following in Eclipse? 如何在Eclipse中点以下内容?

I have created a Android app project in Eclipse and I have put this under version control using eGit and BitBucket (again I don't know if this is the best way to describe it as I'm new to version control). 我已经在Eclipse中创建了一个Android应用程序项目,并使用eGit和BitBucket将其置于版本控制下(再次,我不知道这是描述它的最佳方法,因为我是版本控制的新手)。 I have written some code and made several commits so far. 到目前为止,我已经编写了一些代码并进行了几次提交。 I have invited a friend who has joined the project. 我邀请了一个加入该项目的朋友。 Last night they changed some of the code. 昨晚他们更改了一些代码。

Today I fire up Eclipse and want to continue working on the project, but want to start from where they left off. 今天,我启动Eclipse,并希望继续进行该项目,但希望从他们停下来的地方开始。 I right click on the project and go to Team -> Synchronize (simply because this seemed the most logical step to me). 我右键单击该项目,然后转到“团队->同步”(因为这对我来说似乎是最合逻辑的步骤)。 Nothing happened as I feared. 没有我所担心的发生。

How to I get the latest version of the working code onto my local machine? 如何将最新版本的工作代码下载到本地计算机上? And when I am finished my work, do I just commit as I have been doing by right clicking project and then going to: Team -> Commit followed by Team -> Push to Upstream? 当我完成工作后,是否像往常一样通过右键单击项目然后转到以下位置来提交:团队->提交,然后是团队->推送到上游?

Within Eclipse, start using the Git Repository Explorer perspective, and the Git Staging View. 在Eclipse中,开始使用Git Repository Explorer透视图和Git Staging视图。

The repository explorer shows your clone, allowing you to see your branches, your change history etc. You can right mouse on your clone's name and choose pull. 资源库浏览器显示您的克隆,使您可以查看分支,更改历史记录等。您可以右键单击克隆的名称,然后选择拉。 This will fetch changes from the Bitbucket server and then merge them to your local branch. 这将从Bitbucket服务器获取更改,然后将其合并到本地分支。

Note you should not pull until you have either stashed any locally modified files, or have committed them to your branch. 请注意,在存放任何本地修改的文件或将其提交到分支之前,请勿拉动。 If the pull conflicts with any local changes the action will be rejected. 如果拉取与任何本地更改冲突,则该操作将被拒绝。

As you are sharing a branch with other people you should consider modifying your local (master?) branch via Configure Branch... to enable the Rebase option. 与其他人共享分支时,应考虑通过Configure Branch ...修改本地(主分支)以启用Rebase选项。 This means when you merge remote changes over your local branch, any outgoing commits are replayed over the top of the incoming ones. 这意味着当您在本地分支上合并远程更改时,所有传出的提交都会在传入的提交之上进行重放。 It means when you push you avoid merge points which can clutter up the history. 这意味着当您按下时要避免合并点,因为合并点可能会使历史变得混乱。 Encourage other people working in their own repos to do likewise. 鼓励在自己的存储库中工作的其他人也这样做。

Secondly, when you are committing changes, learn to use the Git Staging view. 其次,在提交更改时,学习使用Git Staging视图。 This makes it easy to drag and drop changes and commit them in a single go. 这样可以轻松地拖放更改并一次提交它们。 You can also do this from Team | 您也可以通过Team | Add and Team | 添加和团队| Commit... but IMO this is far more clumsy. 提交...但是IMO这要笨拙得多。

When you are ready for others to see your committed changes you must push them. 当您准备好让其他人看到您所做的更改时,必须推动它们。 Normally you would either right mouse on a project and choose Team | 通常,您可以在项目上单击鼠标右键,然后选择“团队” |“团队”。 Push to upstream or go to the repository explorer, right mouse on the clone and choose Push to Upstream. 推送到上游或转到资源库浏览器,在克隆上单击鼠标右键,然后选择“推送到上游”。 If necessary you may have to pull before you can push because the server will reject changes if they do not satisfy merge 如有必要,您可能必须先拉动才能进行推送,因为如果服务器不满足合并要求,服务器将拒绝更改

This is the basic workflow of using Git within Eclipse. 这是在Eclipse中使用Git的基本工作流程。 As a general point, also ensure your version of the EGit plugin is at least 2.3.1 or 3.0.1 depending on your version of Eclipse. 通常,还要确保您的EGit插件版本至少为2.3.1或3.0.1,具体取决于您的Eclipse版本。

您无法获取由您的朋友更改的最新代码,可能是因为他更改后但他没有提交..现在,尽管您无法获取更改的代码,但也可以提交更改的代码。因为当他提交时。 ..也许会显示错误,然后您的朋友将您提交的代码更改为他的代码库。

I would recommend against using eGit as I commented here . 在此评论,我建议您不要使用eGit。

If on windows download and install msysgit 如果在Windows上下载并安装msysgit

Then Right click on your eclipse project folder - select Git Bash here and issue 然后右键单击您的Eclipse项目文件夹- 在此处选择Git Bash并发出

$ git pull

The problem with fetch is that it only fetches - pull fetches but also merges the commits it fetched 提取的问题在于,它仅提取-拉取,而且还合并了它提取的提交

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM