本文介绍如何将GitHub和Bitbucket上的repository同步到eclispe。(前段时间,因为对源代码某处误修改,编译没错,但运行时错误,一直找不到哪里修改了源码。为了避免这种情况,决定用git管理代码,方便追踪)
1. 安装插件
在Eclipse安装EGIT, GitHub Mylyn Connector插件。Help –> Install New Software:
EGIT:
http://download.eclipse.org/egit/updatesGitHub Mylyn Connector(我在Marketplaces没装成功): http://download.eclipse.org/egit/github/updates
2. 使用
(1)创建代码创建
直接在网上创建,登录https://github.com/,点击右上角加号,新建repository。创建完,就可以得到形如下的url:
(2)导入GitHub代码仓库
File –> Import –> Git –> Repositories from GitHub, 在搜索框输入github仓库名称,选择相关的repository。
(3)显示Git代码库视图
Windows –> Show View –> Other –> Git –> Git Repositories –> OK.
(4)提交变更
右击相应的软件仓库,Commit…,填入Commit message,点击Commit and Push,输入github用户名和密码,点击OK,代码就提交了。 如下示意图:
(5)从github至eclipse
右击相应的代码仓库,Pull,点击OK就可以了。
(6)回滚
在Eclipse,右击相关的repository –> Show In –> History。在History选项卡中,右击相关的提交 –> Reverse Commit。
命令行操作如下[1],我也没搞透彻:
git revert HEAD~1 # 1表示回到上一次提交
git push origin master
git checkout master
3. Bitbucket
GitHub只有付费才能将代码仓库设为私有,也有一些Githosting无需付费即可设repository为私有,详情见《Public Git hosting sites》。大概了解了下,推荐比较多的是bitbucket。Bitbucket在不付费的情况下就可以将repository设为私有。其git的url形如(红色字体为用户名):
导入到Eclipse的方法跟上述差不多,如下:
File → Import → Git → Projects from Git → Clone URI,输入git的url并在Authentication输入Bitbucket密码,其他操作按提示即可。
4. 其他问题
(1)Entry not found by path
Commit and Push时提示如下错误:
Committing failed
An internal error occurred
Entry not found by path: //ms_system/…/file.php
解决办法:在Git Repo View -> 右击相关的repo -> collect garbage,再重新提交。
参考资料:
[1]Git version control with Eclipse (EGit) – Tutorial
[2]How can I roll back 1 commit?
专题: 代码版本控制 (2/2)
- 版本控制软件、代码托管、SmartGit
- Git代码版本控制:Eclipse+EGIT+GitHub Mylyn Connector
微信赞赏
支付宝赞赏