• gitlab 和 github 仓库操作


    gitlab 和 github 仓库操作

    1、创建公钥

    # 1.在自己linux系统上执行
    ssh-keygen -t ed25519 -C "ssh-key"
    
    # 2.查看公钥
    cat ~/.ssh/id_xxx.pub
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2、将公钥复制在gitlab网站上去

    复制公钥到 个人信息-> Preferences -> SSH Keys

    最后点击保存确定就可以 git clone xxx了

    3、下载好项目后需要切换分支

    4、gitlab 项目操作说明

    1、全局设置

    git config --global user.name "天堑"  && git config --global user.email "wenxu.he@dingxiang-inc.com"
    
    // github
    git config --global user.name "天堑"  && git config --global user.email "1915300275@qq.com"
    
    • 1
    • 2
    • 3
    • 4

    2、创建一个新的仓库

    git clone ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
    cd ot-eye
    git switch -c main
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin main
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    3、压入现有文件夹

    cd existing_folder
    git init --initial-branch=main
    git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
    git add .
    git commit -m "Initial commit"
    git push -u origin main
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    4、压入现有的仓库 ***!!!

    cd existing_repo
    git remote rename origin old-origin
    git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
    git push -u origin --all
    git push -u origin --tags
    
    • 1
    • 2
    • 3
    • 4
    • 5

    5、现有上传完整流程 第一次上传

    # 从无到有 第一次上传
    cd ot-eye
    git init 
    git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
    git add .
    git commit -m "frist upload"
    git branch -M master
    git push -u origin master
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    # 确保有.git
    # git clone ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
    git add .
    git commit -m "Initial commit"
    git remote rename origin old-origin
    git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git
    git push -u origin --all
    git push -u origin --tags
    
    # 一步到位
    git add . && git commit -m "Initial commit" && git remote rename origin old-origin && git remote add origin ssh://git@dev.dingxiang-inc.com:2022/wenxu.he/ot-eye.git && git push -u origin --all && git push -u origin --tags
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    6、更新项目代码

    # 查看是否有更新
    git status 
    git add .
    git commit -m "update"
    git push
    
    # 一步到位
    git add . && git commit -m "update" && git push
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    7、创建分支

    git branch second
    
    # 切换到分支
    git checkout second
    git add . && git commit -m "new branch"
    
    # 上传新分支的代码
    git push origin second
    
    # 下载新分支的代码
    git pull origin second
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    5、github项目管理

    git git config --global user.name <your-name> #输入你github的用户名
    git config --global user.email <your-email> #输入你的邮箱
    
    • 1
    • 2
    #创建ssh key
    ssh-keygen -t rsa -C "1915300275@qq.com"
    
    # 复制公钥
    cat ~/.ssh/id_rsa.pub
    
    # 回到github网址,依次选择:点击自己头像下的Settings-->SSH and GPG keys –> New SSH key”,随便填个title,然后把刚刚复制的内容黏贴上去就可以了。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5.1 在项目目录操作

    # 从无到有 第一次上传
    git init 
    git remote add origin ssh://git@dev.dingxiang-inc.com:2022/shuhai.hu/docker-images.git
    git add .
    git commit -m "frist upload"
    git branch -M master
    git push -u origin master
    
    # 一步到位
    git add . && git commit -m "frist upload" && git branch -M master && git push -u origin master
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    5.2 更新代码

    # 一步到位
    git add . && git commit -m "update" && git push
    git add . && git commit -m "无聊更新了一下" && git push
    
    # 拉取代码
    git remote add upstream git@github.com:NineSunTaoist/offer-exam.git
    git fetch upstream && git merge upstream/master
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5.3 切换历史版本

    # 查看历史版本
    git log
    
    # 排序HEAD查看历史版本
    git reflog
    # 恢复到上一条指令所选的ID版本
    git reset --hard [commit_ID]
    
    # HEAD可以用来替换commit_id,HEAD指向的版本是当前版本,上一个版本就是HEAD^ ,上上一个版本就是HEAD^^ ,往上100个版本写成HEAD~100。
    
    # 查看最新版本修改的内容
    git log --stat
    git show [commit_id]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    5.4 git 打标签

    # 查看标签
    git tag
    git tag -l
    
    # 打上附属标签
    git tag -a v2.0 -m "OT-Phantom version 2.0"
    
    # 删除标签
    git tag -d v2.0
    
    # 推送标签
    git push origin v2.0
    
    # 删除远程仓库的标签
    git push origin :refs/tags/v2.0
    git push origin --delete v2.0
    
    # 推送所有
    git push
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    打标签参考连接:

    https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE

    5.5 git 设置默认分支

    # 显示项目有哪些分支
    git remote show origin
    
    # 设置一个分支为默认分支  无效
    git branch --set-upstream-to=origin/TianQian TianQian
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    C++ opencv实现letterbox
    DockerCompose部署es和kibana
    LLM - 绝对与相对位置编码 与 RoPE 旋转位置编码 源码
    地理信息系统原理重点整理
    eslint错误修改之后依然报错
    『NLP学习笔记』图解GPT3(How GPT3 Works-Visualizations and Animations)
    边缘计算:推动智能时代的前沿技术
    Rocky(centos)安装nginx并设置开机自启
    奇安信 测试|测试开发 面试真题|面经 汇总
    深入浅出 多线程编程(2)
  • 原文地址:https://blog.csdn.net/qq_31507523/article/details/125462212