在Myeclipse中使用git

1、下载Eclipse的git插件——EGit。下载网址http://download.eclipse.org/egit/updates-1.3/org.eclipse.egit-updatesite-1.3.0.201202151440-r-site.zip ,这是截至目前最新版的,如果想下更新版本,访问EGit的下载页面 http://www.eclipse.org/egit/download/ 即可。

2、安装插件:把上一步下载的插件解压出来,删掉XML文件。在MyEclipse的dropins目录下新建一个egit文件夹,然后把刚才解压的 features、plugins和另外两个jar包全放进去。重启MyEclipse后,进入window-preferences-team,看到 Git选项,就说明安装成功了。

3、下载git环境:进入 http://msysgit.github.io/下载Git,安装好之后,即可使用Git Bash。这个在后面要用到。

4、进入https://github.com ,用你的邮箱申请帐号,略去不表。

5、注册成功后,可以新建一个项目:点击页面上的new repositories按钮,填写项目名、描述等信息即可,这个项目是要装你在本地要上传的项目。例如你建了个项目叫helloworld。

6、设置一下你的SSH Key信息,这步很重要,否则项目是提交不上去的。

  • 从你的开始菜单里打开Git Bash。
  • 在$提示符后面,输入 ssh-keygen -t rsa -C "your_email@youremail.com" 回车,注意:ssh-keygen是连着写的,中间没有空格,"your_email@youremail.com"是你在github中注册的邮箱。
  • 这时候系统会提示你一些问题,比如passphrase什么的,一路回车过去就行了。
  • 最后系统会生成一个id_rsa.pub文件,里面就是你的SSH Key了。这个文件默认是存放在C:\Documents and Settings\Administrator\.ssh文件夹里。
  • 进入Github网站,在 https://github.com/settings/ssh 页面中,点击“ADD SSH KEY”按钮,把id_rsa.pub文件里的内容复制到里面,title随便写个就行。
  • 至此,SSH Key就设置好了。

7、从MyEclipse中选择或新建一个工程,例如你在c:\prj文件夹中有了一个工程叫helloworld。

8、下面就是按照提示,创建自己的第一个README文件了。

  1. 从你的开始菜单里打开Git Bash。
  2. 依次输入以下命令
  3.  1     $git config --global user.name"你的用户名"    注:可以不是你帐号   
     2       
     3     $git config --global user.email"你的email"    注:注册的帐号  
     4       
     5     $cd c://prj//helloworld 注:就是你从myeclipse里创建的工程目录  
     6       
     7     $git init   //设置该目录为推送
     8       
     9     $touch README  //生成readme
    10       
    11     $git add README  //加入修改列表
    12       
    13     $git commit -m 'first commit'    //递交修改声明
    14       
    15     $git remote add origingit@github.com:<你的帐号>/helloworld.git  //为远程Git更名为origin
    16       
    17     $git push –u origin master  //推送此次修改

     

  4. 如果顺利的话,你从Github网站上能看到你上传的那个README文件了。
  5. 如果前面第7步的SSH Key设置不正确,上面的命令可能会提示Permission denied (publickey)
  6. 然后各种问题从这里开始了,以下谈一下解决的方法:

 

问题一:

如果输入$ git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git 

    提示出错信息:fatal: remote origin already exists.

    解决办法如下:

    1、先输入$ git remote rm origin

    2、再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!

    3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

    4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

    5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

问题二:

 如果输入$ git push origin master

 提示出错信息:error:failed to push som refs to .......

 解决办法如下:

    1、先输入$ git pull origin master //先把远程服务器github上面的文件拉下来

    2、再输入$ git push origin master

    3、如果出现报错 fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.

    4、则需要重新输入$ git remote add origingit@github.com:djqiang/gitdemo.git

 

8、前面几步都搞定的话,下面可以进入MyEclipse,使用EGit插件进行项目管理了。

 

参考文献

http://blog.csdn.net/softwave/article/details/7622790

http://blog.163.com/023_dns/blog/static/1187273662013111301046930/

 

posted @ 2014-06-02 21:51  GYI_Feison  阅读(922)  评论(0)    收藏  举报