美文网首页
Git 基础

Git 基础

作者: SmallTank_2017 | 来源:发表于2017-09-26 12:04 被阅读0次

    git 提交

    • 自报家门
     $ git config --global user.name '名字'
     $ git config --global user.email '邮箱'
    
    • cd 到需要创建仓库的地方,创建仓库
    cd e:/
    mkdir test
    cd test
    git init    # 创建仓库
    
    • 把文件移到仓库中后
    git status  #查看仓库状态
    git add .   #.代表提交当前目录所有文件,提交到暂存区。git add index.txt提交单个文件
    git commit -m “test提交”  # 提交到版本库。"test提交" 为提交的注释
    

    git 删除

    git rm delete.txt                # 删除文件
    git commit -m "删除delete.TXT"  # 提交删除操作
    

    推送到远程仓库

    • 先在github创建仓库,得到 https 地址
    git push https://github.com/SmallTankpy/lianshou.git master  
    
    • 提交代码到github仓库 本地master主分支 需要输入username password
    • 为本地仓库添加远程仓库和别名
    git remote add lianshou https://github.com/SmallTankpy/lianshou.git
    
    • 意思是:添加一个远程仓库,代号为lianshou,地址是...lianshou.git
    • 改动后再次提交,到仓库目录
    git add .
    git commit -m 'lianshou别名'
    git push lianshou master   # lianshou 是远程仓库的别名 master 是本地分支的名字
    
    • 查看远程仓库地址别名
    git remote -v
    git remote remove "别名"   # git remote remove origin
    

    团队合作

    # 克隆github仓库该地址的项目到指定位置
    cd e:
    git clone git@github.com:SmallTankpy/lianshou.git  
    
    • 把项目最新版本 pull(拉) 下来
    cd e:/test     # cd 目录
    git pull lianshou master
    

    查看日志

    git log         # 日志包括作者 日期 版本号等
    git log --pretty=oneline   # 查看日志 简化为一行
    

    版本回退、版本控制

    git reflog     # 查看所有版本操作日志
    git reset --hard “版本号”  # 版本切换
    

    分支

    git branch     # 查看分支
    git branch "分支名"   # 创建分支  例: git branch tank
    git checkout "分支名" # 切换分支  例: git checkout tank
    
    • 合并分支
    git checkout master  # 切换到master 分支
    git merge "分支名"   # 合并分支到master  例: git merge tank
    
    • 删除分支
     git branch -d "分支名"    # git branch -d ali
    

    创建 公钥 就不用密码提交了

     ssh-keygen -t rsa -C "381784363@qq.com"
    # id_rsa 是私钥 
    # id_rsa.pub 是公钥,公钥复制到Github上 SSH方式push
    

    相关文章

      网友评论

          本文标题:Git 基础

          本文链接:https://www.haomeiwen.com/subject/qursextx.html