美文网首页
git常用命令

git常用命令

作者: 马小帅mm | 来源:发表于2018-08-17 17:24 被阅读0次

    Git 命令行

    Git 的工作原理
    参考: https://git-scm.com/book/zh/v2

    1. 配置全局的用户名称与邮件地址

    $ git config --global user.name "mxp"
    $ git config --global user.email maxaingping_lb@163.com
    

    2. 检查你的配置

    $ git config --list    //检查所有配置项
    $ git config user.name   //检查其中一项
    

    3. 克隆项目

    $ git clone https://github.com/libgit2/libgit2 mylibgit
    

    4. 查看状态

    $ git status
    

    5. 查看文件的差异

    $ git diff
    $ git diff --cached  //查看已经暂存起来的变化
    

    6. 暂存文件

    $ git add .
    

    7. 提交到本地存储 -a 跳过暂存步骤 -m 添加提交注释

    $ git commit -am ‘mxp’
    

    8. 从暂存区域移除文件

    $ git rm --cached index.html
    

    9. 查看提交历史

    $ git log
    $ git log --pretty=oneline
    

    10. 新建testing分支

    $ git branch testing
    

    11. 切换到testing分支

    $ git checkout testing
    

    12 本地分支和远程分支的关联

    git branch --set-upstream-to=origin/feature/data_configure  feature/data_configure
    

    13.回退本地分支:Obfafd是要回退的版本号

    git reflog
    git reset --hard Obfafd
    

    14.强制推送到远程分支:

    git push -f origin master ## 这里假设只有一个master分支
    

    15.Git Reset hard误操作回滚恢复代码

    1.找到要恢复的版本号
    .git/logs/refs/heads/分支名称
    2.输入git reset --hard 版本号
    3.强制推上去  git push -f
    

    16.搜索所有分支中包含'unescape(r[2])'字符串的分支

    git log -S'unescape(r[2])'
    

    17.合并testing分支到当前分支:

    git merge --no-ff -m "添加注释”  testing
    //--no-ff 参数就可以用普通模式合并,合并后的历史有分支,能看出来曾经做过合并
    //-m “添加注释” 表示创建一个新的commit
    

    相关文章

      网友评论

          本文标题:git常用命令

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