美文网首页
常用 Git 命

常用 Git 命

作者: 锄禾日当 | 来源:发表于2016-10-15 19:01 被阅读37次

    专用名次解释

    • Workspace:工作区
    • Repository:仓库区(或本地仓库)
    • Remote:远程仓库
    • Index / Stage:暂存区

    新建代码库

    在当前目录新建一个Git代码库
    $git init
    新建一个目录,将其初始化为Git代码库
    $git init[project_name]
    下载一个项目和代码历史
    $git clone[url]
    

    配置

    • .git.config为Git的设置文件,它可以为全局配置(用户主目录下)、项目配置(项目目录下)
    显示当前Git的配置
    $git config --list
    编辑Git的配置文件
    $git config -e [global]
    设置提交代码的用户信息
    $git config [--global] user.name "[name]"
    $git config [--global] user.name "email address"
    

    增加/删除文件

    添加指定文件到暂存区
    $git add [file1] [file2]...
    添加指定文件到暂存区,包括子目录
    $git add [dir]
    添加当前目录的所有文件到暂存区
    $git add
    删除工作区文件,且将此次删除的文件放入暂存区
    $git rm [file1] [file2]...
    停止追踪指定文件,但该文件保存在工作区
    $git rm -cached [file]
    文件改名,且将改名文件放入暂存区
    $git mv [file-original] [file-renamed]
    

    提交代码

    提交暂存区到仓库区
    $git commit -m [message]
    提交暂存区的指定文件到仓库区
    $git commit [file1] [file2]... -m [message]
    提交工作区自上次commit之后的变化,直接到仓库区
    $git commit -a
    提交时显示所有的diff信息
    $git commit -v
    使用一次新的commit,替代上一次提交
    如果代码未发生变化,则用来改写上一次的commit的提交信息
    $git commit --amend -m [message]
    重做上一次的commit,并包括指定文件的新变化
    $git commit --amend [file1] [file2]...
    

    url

    相关文章

      网友评论

          本文标题:常用 Git 命

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