CentOS安装Git eclipse代码同步

我参考的文章,写的很详细:

https://www.cnblogs.com/YingYue/p/6058333.html?utm_source=itdadao&utm_medium=referral

1:服务器安装git 依赖:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

   安装git 执行命令 yum install -y git (-y表示安装过程中不需要手动确认可以不加那么安装过程中需要输入y手动回车确认)

2:创建”用户组“和”用户“,用来运行git服务。

创建用户组: groupadd java_team

  创建用户并yingyue添加到名为”java_team“的组中: adduser whl -java_team

   为用户名为yingyue的用户设置密码: passwd whl

3:安装Git客户端(开发人员安装)

下载地址https://git-scm.com/downloads 目前最新版本为:Git-2.10.2-64-bit.exe

生成公钥。安装后鼠标右键,如下:help->Show SSH Key

4:创建证书登录:
    5.1 在用户 whl .ssh目录下创建authorized_keys文件
        [root@localhost zhoujianxu]# cd /home/whl/
        [root@localhost whl]# mkdir .ssh
        [root@localhost whl]# ls -la
        [root@localhost whl]# chmod 740 .ssh
        [root@localhost whl]# touch .ssh/authorized_keys
        [root@localhost whl]# chmod 600 .ssh/authorized_keys
    5.2 id_rsa.pub 公钥添加到authorized_keys文件中 : cat id_rsa.pub >> .ssh/authorized_keys
5:服务器上初始化Git仓库,并把权限改为自己可读写执行,组不能写,其他没有权限
 
 
  [root@localhost home]# mkdir git_repository
 
 
  [root@localhost home]# chown whl:java_team git_repository
 
 
  [root@localhost home]# cd git_repository/
  [root@localhost git_repository]# git init --bare cms.git
  [root@localhost git_repository]# chmod 750 cms.git
  [root@localhost git_repository]# cd ..
 
 
  [root@localhost git_repository]# chmod 750 git_repository
 
 
  修改文件的所属组(权限向下递归更改为所属用户为whl所属组为java_team。):chown -R whl:java_team cms.git  

6:使用Git Bash克隆服务器上的空仓库

git 先切换到你想存项目的位置。我是存到e盘: cd /e

格式git clone [user@]example.com:/*/*.git/

git clone whl@ip:/home/git_repository/cms.git/

就成功了。(我遇到的一个问题。我的腾讯云服务器开始是设置的只能用秘钥登录,不能用密码,就导致连接总是被拒绝。解决办法是暂时取消服务器绑定秘钥,改用密码!坑啊)

7:将本地库推送到服务器

    1)将eclipse中的cms项目复制到cms目录里(在你刚刚git的位置,我的就在e盘里)

    2)git add .把整个cms项目内文件的信息添加到索引库中,使用git commit命令提交。(git将依据索引库中的内容来进行文件的提交)

   3)执行git push -u origin master命令将本地cms_repository库的文件提交到远程服务器

   搞定啦。你的项目已经同步到服务器了。

8:导入本地Git库的项目到eclipse

   import->git->Project from Git->Exising local repository->add->browse->finish->import existing eclipse project-    finish.搞定啦。图片过程参考最上面的链接。





猜你喜欢

转载自blog.csdn.net/qq_16753341/article/details/80321974