• git


    bash

    服务 ip /主机名 功能
    gitlab gitlab 10.0.0.203 master分支
    jenkins jenkins01 10.0.0201 dev1分支

    项目用户组关联

    创建test组

    image-20200416003235500

    image-20200416003301368

    创建dev1用户

    image-20200416004351445

    image-20200416004451438

    image-20200416004623613

    把dev1用户关联到test组

    image-20200416004815390

    image-20200416005005506

    image-20200416005013403

    创建docker项目,把test组添加到项目里

    image-20200416005058518image-20200416005422006

    仓库使用命令

    1. 全局配置

    git config --global user.name "dev1"
    git config --global user.email "314108534.com"
    
    1. ​ Create a new repository#创建新的空仓库

    git clone git@gitlab.john5.com:test/docker.git
    cd docker
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master
    
    1. ​ Push an existing folder #以存在的文件夹执行以下操作

    cd existing_folder
    git init
    git remote add origin git@gitlab.john5.com:test/docker.git 
    #添加1个远程仓库
    git add .
    git commit -m "Initial commit"
    git push -u origin master
    
    1. ​ Push an existing Git repository 存在的仓库

    cd existing_repo
    #重命名
    git remote rename origin old-origin
    
    git remote add origin git@gitlab.john5.com:test/docker.git
    git push -u origin --all
    git push -u origin --tags
    

    master分支操作,

    从github拉代码

    复制[root@gitlab ~]的公钥到github把代码拉到本地 打通 ssh连接

    [root@gitlab ~]#git clone git@github.com:john20105/docker.git
    Cloning into 'docker'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 12 (delta 0), reused 2 (delta 0), pack-reused 9
    Receiving objects: 100% (12/12), done.
    Resolving deltas: 100% (1/1), done.
    

    查看名字是origin是github上的仓库名

    此时相当与本地有仓库了

    [root@gitlab docker]#git remote 
    origin
    [root@gitlab docker]#git remote  -v
    origin	git@github.com:john20105/docker.git (fetch)
    origin	git@github.com:john20105/docker.git (push)
    

    从github拉代码到本地复制这个地址

    复制这个地址

    image-20200416012029018

    给从github下来的仓库添添加了个名字叫 gitlab

    [root@gitlab docker]#git remote add gitlab git@gitlab.john5.com:test/docker.git
    

    现在这个仓库有2个名字,如下

    [root@gitlab docker]#git remote -v
    gitlab	git@gitlab.john5.com:test/docker.git (fetch)
    gitlab	git@gitlab.john5.com:test/docker.git (push)
    origin	git@github.com:john20105/docker.git (fetch)
    origin	git@github.com:john20105/docker.git (push)
    [root@gitlab docker]#git remote 
    gitlab
    origin
    

    推送到gitlab

    [root@gitlab docker]#git push -u gitlab master 
    Counting objects: 12, done.
    Compressing objects: 100% (10/10), done.
    Writing objects: 100% (12/12), 2.14 KiB | 0 bytes/s, done.
    Total 12 (delta 1), reused 12 (delta 1)
    To git@gitlab.john5.com:test/docker.git
     * [new branch]      master -> master
    Branch master set up to track remote branch master from gitlab.
    

    master分支查看有了数据

    image-20200416012830280

    把gitlab上面的参考复制到jenkins01机器

    打通ssh连接

    [root@jenkins01 ~]#ssh-keygen -t rsa -f ~/.ssh/dev1_rsa -C "dev1"
    
    [root@jenkins01 .ssh]#cat dev1_rsa.pub 
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85IY+jAsl0mzjq7ltq69R8gshx3UGCLhdZhabYs1Vb5rNoQpDC2GSfjKFqArj9tK1TcX50Cz7fmv+uh9n8bExM1lL6czEKgVwn5amIHc3Rdewu0JMA529AkMwc1wLbNwa8nS7
    TO1bzn3uZnCtFSq2Ktm5q1hdfvfus0uAMXq0666oDJmDlqccCsanD9BrGyX6Hup9gXjFCCngSbIGJNk3kzSEcED9toXx474d9zjIa3gRuML2Qs+mxe8exWSas9k3PoWJPg/F2/LzWxydrSD+wDYdlqtlHao+LKs6dbeo7S1W8rqduEej8ZE1GmKoMYc/N0dMuEV0dZiqaOPtezh3 dev1
    

    复制公钥到gitlab dev1用户下

    image-20200416013718725

    拉代码到dev1用户

    ​ git clone git@gitlab.john5.com:test/docker.git

    [root@jenkins01 ~]#git clone git@gitlab.john5.com:test/docker.git
    Cloning into 'docker'...
    remote: Enumerating objects: 12, done.
    remote: Counting objects: 100% (12/12), done.
    remote: Compressing objects: 100% (11/11), done.
    remote: Total 12 (delta 2), reused 0 (delta 0)
    Receiving objects: 100% (12/12), done.
    Resolving deltas: 100% (2/2), done.
    

    查看只有分支master

    • [root@jenkins01 docker]#git branch 
      * master
      

    模拟创建dev1分支,在dev1分支做修改,提交到dev1分支

    [root@jenkins01 docker]#git branch dev1
    [root@jenkins01 docker]#git checkout dev1
    Switched to branch 'dev1'
    

    增加文件并提交

    [root@jenkins01 docker]#touch dev1file
    [root@jenkins01 docker]#git add .
    [root@jenkins01 docker]#git commit -m "dev1 add file"
    [dev1 b8bf2f3] dev1 add file
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 dev1file
     
    

    推送到dev1分支成功

    ​ git push -u origin dev1

    	[root@jenkins01 docker]#git push -u origin dev1 
    Counting objects: 4, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 257 bytes | 0 bytes/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: 
    remote: To create a merge request for dev1, visit:
    remote:   http://gitlab.john5.com/test/docker/merge_requests/new?merge_request%5Bsource_branch%5D=dev1
    remote: 
    To git@gitlab.john5.com:test/docker.git
     * [new branch]      dev1 -> dev1
    Branch dev1 set up to track remote branch dev1 from origin.
    

    docker项目web页面查看 多了dev1分支

    dev1用户登录,查看多了2个文件

    image-20200416103951176

    image-20200416103928573

    切换到master分支进行合并,这2不没用

    ​ 由jenkins01机器的公钥绑定在 dev用户,dev用户没有权限往master推代码 所以推送失败

    [root@jenkins01 docker]#git checkout master 
    Switched to branch 'master'
    
    [root@jenkins01 docker]#git merge dev1 
    Updating 0af591c..b8bf2f3
    Fast-forward
     dev1file | 0
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 dev1file
     
     
    [root@jenkins01 docker]#git push -u origin master 
    Total 0 (delta 0), reused 0 (delta 0)
    remote: GitLab: You are not allowed to push code to protected branches on this project.
    To git@gitlab.john5.com:test/docker.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'git@gitlab.john5.com:test/docker.git'
    

    切换到绑定gitlab服务root用户,合并 此时mster分支数据过于老,需要fetch

    [root@gitlab docker]#git fetch 
    

    创建dev1分支 gitlab上的代码pull下来

    [root@gitlab docker]#git checkout dev1
    [root@gitlab docker]#git pull origin dev1 
    

    切换到master分支

    [root@gitlab docker]#git checkout master 
    Switched to branch 'master'
    

    合并dev1分支

    [root@gitlab docker]#git merge dev1 
    Updating 0af591c..c68dbff
    Fast-forward
     dev1fiel | 0
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 dev1fiel
    
    

    推送到master

    [root@gitlab docker]#git push -u oirgin master 
    Total 0 (delta 0), reused 0 (delta 0)
    To git@gitlab.john5.com:test/docker.git
       0af591c..c68dbff  master -> master
    Branch master set up to track remote branch master from oirgin.
    

    查看数据合并到了master分支

    [root@gitlab docker]#ll
    total 16
    -rw-r--r-- 1 root root   0 Apr 17 20:22 dev1file
    -rw-r--r-- 1 root root 422 Apr 17 20:13 dockerfile
    -rw-r--r-- 1 root root  34 Apr 17 20:13 init.sh
    -rw-r--r-- 1 root root 356 Apr 17 20:13 nginx.repo
    -rw-r--r-- 1 root root 103 Apr 17 20:13 tc1.conf
    

    image-20200418112511129

    image-20200418112522627

    web界面点击合并

    image-20200417223643228image-20200417223648463image-20200417223652650image-20200417223658365

    tag

    创建tag示例

    [root@gitlab docker]#touch aaa
    [root@gitlab docker]#git add .
    
    
    [root@gitlab docker]#git commit -m "master add aaa"
    [master 0aed20d] master add aaa
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 aaa
    
    
    [root@gitlab docker]#git push -u origin master 
    Counting objects: 4, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 258 bytes | 0 bytes/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    To git@gitlab.john5.com:test/docker.git
       c50a78e..0aed20d  master -> master
    Branch master set up to track remote branch master from origin.
    
    

    查看bbb的哈希值

    [root@gitlab docker]#git log --oneline 
    3def1c0 master add bbb
    0aed20d master add aaa
    c50a78e del tag
    

    给hash值打标

    [root@gitlab docker]#git tag -a "v1.0" 0aed20d -m "master add aaa"
    

    把标签推到远程master

    • [root@gitlab docker]#git push -u origin master v1.0 
      Counting objects: 1, done.
      Writing objects: 100% (1/1), 158 bytes | 0 bytes/s, done.
      Total 1 (delta 0), reused 0 (delta 0)
      To git@gitlab.john5.com:test/docker.git
      
       * [new tag]         v1.0 -> v1.0
         Branch master set up to track remote branch master from origin.
      

    查看标签详情

    [root@gitlab docker]#git show v1.0  
    tag v1.0
    Tagger: john5 <314108534@qq.com>
    Date:   Fri Apr 17 23:30:26 2020 +0800
    
    master add aaa
    commit 0aed20d9674b59ae9d3f48a7d3646e59f165bf4f
    Author: john5 <314108534@qq.com>
    Date:   Fri Apr 17 23:22:53 2020 +0800
    
        master add aaa
    
    diff --git a/aaa b/aaa
    new file mode 100644
    index 0000000..e69de29
    
    

    删除远程标签

     git push origin :refs/tags/v1.0
     git push origin :refs/tags/v2.0
    

    dev1分支查看多了tags v1.0标签,代表v1.0某个版本,查看操作很方便

    image-20200416215639879

    image-20200416215700408

    gitlab备份恢复

    image-20200416220631246

    ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C “Key for Gitlab stuff”

  • 相关阅读:
    聊天工具分享bug
    Git命令查看代码提交次数
    短链接生成实例
    .Net MVC用户注册验证码
    js写验证码
    笔记
    jq获取数组中的某个字段拆分成字符串。
    IIS部署后中文Cookie乱码
    C#反射(Reflection)与特性(Attribute)实例
    jmm
  • 原文地址:https://www.cnblogs.com/john5yang/p/12725798.html
Copyright © 2020-2023  润新知