美文网首页
git简单使用

git简单使用

作者: 海洋之巅 | 来源:发表于2019-01-21 16:00 被阅读0次

    设置基本信息。

    git config --global user.name "yourname"
    git config --global user.email "youremail@youremail.com"
    

    初始化本地库

    将你的远程仓库克隆到本地,或者你可以在本地初始化一个项目后再进行云端绑定。

    • 直接从远程仓库克隆到当前文件夹,自动在当前文件夹下创建项目文件夹
    git clone https://gitee.com/yourname/repository.git
    

    yourname 您在码云或gitee注册的用户名
    repository 您创建的远程仓库名称

    • 本地初始化,自己创建并进入项目文件夹
    //首先在文件系统中创建一个项目文件夹,然后在Git中 cd 到这个工程目录
    cd <文件夹>     
    //初始化本地项目
    git init          
    //绑定远程仓库
    git remote add origin <远程仓库地址>      
    

    注:地址形式为 https://gitee.com/yourname/test.git
    注:origin就替换了 https://gitee.com/yourname/test.git

    更新到远程仓库

    //指定更新内容    . 表示全部更新,test.txt 表示更新指定文件
    git add .   
    //添加更新说明
    git commit -m "一些注释说明"     
    //执行更新操作
    git push origin master            
    

    从远程仓库同步最新版本到本地

    cd /d/test
    git pull origin master
    

    git常用命令

    //用于查看提交日志
    git log            
    //单行查看commit日志                         
    git log --pretty=oneline     
    //查询绑定的远程仓库          
    git remote -v 
    //回到上个commit版本,一个^表示回退一个版本,可添加多个
    git reset --hard HEAD^ 
    //回到某个commit版本
    git reset --hard commitID 
    //查看每一次git操作,一般用于寻找commit id
    git reflog
    

    1.添加用户名和git账号邮箱

    git config --global user.name "username"
    git config --global user.email "youremailname@youremail.com"

    2.初始化本地项目

    cd <文件夹>
    git init

    3.设置绑定远程仓库

    git remote add origin <远程仓库url>

    4.删除远程仓库

    git remote rm origin/<远程仓库url>

    5.推送代码到远程仓库

    git add .
    git commit -m "一些注释说明"
    git push origin/<远程仓库url> master

    6.从远程仓库拉取代码

    git pull origin/<远程仓库url> master

    7.git pull 错误 :error: The following untracked working tree files would be overwritten by merge:
    .DS_Store.Please move or remove them before you merge.

    git clean -d -fx

    8.git stash 暂存修改的代码,然后进行 git pull ,再解封暂存的代码 git stash apply --index
    参考链接:https://www.cnblogs.com/yiven/p/8465054.html

    相关文章

      网友评论

          本文标题:git简单使用

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