美文网首页
git常用命令

git常用命令

作者: 铁了个铁 | 来源:发表于2017-09-28 00:13 被阅读15次

    初始配置

    git config --global user.name name        // 设置用户名
    git config --global user.email email        // 设置email
    git config --global push.default simple        // 选择最安全的push方式
    git config --global core.quotepath false        // 防止文件名变成数字
    git config --global core.editor "vim"        // 使用vim编辑器
    

    常用命令

    git init        // 初始化(当前目录下创建.git目录)
    git status -s        // 查看git状态(s代表以简短格式显示)
    git add filename        // 将文件更改纳入git控制范围
    git rm filename        // 删除文件,-f覆盖最新版本,-r递归删除
    git commit -v        // 将文件更改添加到版本库(存入.git目录)
    git log        // 展示历史
    git show commitcode        // 根据commit编码查看更改的内容
    git remote add origin xxxxx        // 将本地仓库链接至一个远程库
    git remote set-url origin xxxxx        // 更改链接的远程库
    git push -u origin master        // 将本地master分支与远程master分支连接
    git pull        // 更新本地仓库(.git)和本地文件
    git clone        // 克隆git仓库
    git stash        // 将没有提交的更改临时储存起来
    git stash list      // 查看stash储存的内容
    git stash pop        // 恢复并删除stash储存的内容
    git branch        // 查看分支
    git branch <name>        // 创建分支
    git branch -d <name>        // 删除分支
    git checkout <name>        // 切换至分支
    git checkout -b <name>        // 创建并切换新的分支
    git merge <name>        // 合并某分支到当前分支
    git reset --hard commit_id        // 将代码恢复至指定的历史版本
    git reflog        // 查看历史命令
    

    git操作原则

    1. git push 之前必须 git pull
    2. git pull 之前必须 git commit
    3. git commit 之前必须 git add
    

    vim基本操作

    i        // 编辑模式
    esc        // 退出编辑模式
    :wq        // 退出vim
    
    

    相关文章

      网友评论

          本文标题:git常用命令

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