git部署

来自于:https://blog.csdn.net/qq_33285730/article/details/64125758

    初始化
    git init 会有工作区目录
    git --bare init 只有裸仓库,没有实际代码,只记录提交了那些文件
    CentOS7.0 git 部署
    若无安装git yum install git
    进入需要变成仓库目录 以下均以 /phpstudy/www/test 为例 test就是一个项目
    1.初始化仓库
    [root@iZuf66ezpf4kttqxghdu5zZ test]# git init
    Initialized empty Git repository in /phpstudy/www/test/.git/
    以上提示 初始化仓库成功
    2.创建一个git用户,git登陆上传是ssh,所以要创建一个用户
    [root@10-9-44-81 /]# useradd git
    [root@10-9-44-81 /]# passwd git
    克隆时需要输入的密码,就是上方设置的时候输入的密码 好像可为空
    3.将仓库所属改为git
    [root@iZuf66ezpf4kttqxghdu5zZ test]# cd ../
    [root@iZuf66ezpf4kttqxghdu5zZ www]# chown -R git:git test/
    这时候已经搭建完毕了
    4.在另一台机器上clone这个空代码库
    Administrator@X6X8-20160914QY MINGW32 /d/wamp/www
    $ git clone [email protected]:/phpstudy/www/test/
    Cloning into 'test'...
    [email protected]'s password:
    warning: You appear to have cloned an empty repository.
    Checking connectivity... done.
    这时候就已经克隆完毕了

    **git 命令**
    git add 文件名 提交单独文件
    git add -A . 提交所有文件
    git commit -m " 这里是对此次提交的说明 例如:首页新增页面" add 命令就是提交文件到暂存库
    git push origin 分支名 提交代码到远端分支
    git pull 拉取最新的代码
    git merge 分支名 合并某分支
    git log 查看提交历史
    git reset --hard 哈希值 还原到某个历史 哈希值在git log里有对应的很长一段值的
    git clean 清空暂存区

git问题总结

    error: failed to push some refs to 可能是目录归属组没有归到git下
    设置完组后,若推送出现以下
    Administrator@X6X8-20160914QY MINGW32 /d/wamp/www/niu-operate (linwq)
    $ git push origin linwq
    [email protected]'s password:
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 255 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    error: Unable to append to ./logs/refs/heads/linwq: Permission denied
    To [email protected]:/phpstudy/www/niu-operate/
    ! [remote rejected] linwq -> linwq (failed to write)
    error: failed to push some refs to '[email protected]:/phpstudy/www/niu-operate/'
    问题: 服务器该目录下 .git/没有权限
    执行 chmod -R 777 .git/

生成SSH-KEY

    设置Git的user name和email:
    [root@10-9-44-81 /]# git config --global user.name "levislin"
    [root@10-9-44-81 /]# git config --global user.email "[email protected]"
    二、生成SSH密钥过程:
    1.查看是否已经有了ssh密钥:cd ~/.ssh
    如果没有密钥则不会有此文件夹,有则备份删除
    2.生存密钥:
    [root@10-9-44-81 /]# ssh-keygen -t rsa -C "[email protected]"
    按3个回车,密码为空。
    Your identification has been saved in /home/tekkub/.ssh/id_rsa.
    Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
    The key fingerprint is:
    ………………
    最后得到了两个文件:id_rsa和id_rsa.pub
    管理公钥
    创建 .ssh/authorized_keys

安全性 禁用shell登录:

    出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:
    git:x:1001:1001:,,,:/home/git:/bin/bash
    改为:
    git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
    这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。
    ##### 如果中途需要忽略文件 .gitignore 不生效的情况下
    [root@10-9-44-81 /]# git rm -r --cached .

/homt/git: Permission denied

    [root@10-9-44-81 /]# chown -R git:git /home/git/

修改ssh 端口 22 变成 10086

    #修改ssh 端口 22 变成 10086
    git remote set-url origin ssh://[email protected]:10086/phpstudy/www/yiyisoft/

更新文件索引

    git rm -r --cached .
    git add .
    git commit -m 'update .gitignore'

猜你喜欢

转载自blog.csdn.net/m0_38087224/article/details/85017323