美文网首页
git的基本使用

git的基本使用

作者: 疯中 | 来源:发表于2018-04-27 17:07 被阅读0次

git的基本使用

一、概述

先用一幅图,从总体上描述主要git命令的工作流程

  • workspace: 本地的工作目录。(记作A)
  • index:缓存区域,临时保存本地改动。(记作B)
  • local repository: 本地仓库,只想最后一次提交HEAD。(记作C)
  • remote repository:远程仓库。(记作D)

二、命令笔记

以下所有的命令的功能说明,都采用上述的标记的A、B、C、D的方式来阐述。

初始化

  • git init //创建
  • git clone /path/to/repository //检出
  • git config --global user.email "you@example.com" //配置email
  • git config --global user.name "Name" //配置用户名

操作

  • git add <file> // 文件添加,A → B
  • git add . // 所有文件添加,A → B
  • git commit -m "代码提交信息" //文件提交,B → C
  • git commit --amend //与上次commit合并, *B → C
  • git push origin master //推送至master分支, C → D
  • git pull //更新本地仓库至最新改动, D → A
  • git fetch //抓取远程仓库更新, D → C
  • git log //查看提交记录
  • git status //查看修改状态
  • git diff//查看详细修改内容
  • git show//显示某次提交的内容

撤销操作

  • git reset <file>//某个文件索引会回滚到最后一次提交, C → B
  • git reset//索引会回滚到最后一次提交, C → B
  • git reset --hard // 索引会回滚到最后一次提交, C → B → A
  • git checkout // 从index复制到workspace, B → A
  • git checkout -- files // 文件从index复制到workspace, B → A
  • git checkout HEAD -- files // 文件从local repository复制到workspace, C → A

分支相关

  • git checkout -b branch_name //创建名叫“branch_name”的分支,并切换过去
  • git checkout master //切换回主分支
  • git branch -d branch_name // 删除名叫“branch_name”的分支
  • git push origin branch_name //推送分支到远端仓库
  • git merge branch_name // 合并分支branch_name到当前分支(如master)
  • git rebase //衍合,线性化的自动, D → A

冲突处理

  • git diff //对比workspace与index
  • git diff HEAD //对于workspace与最后一次commit
  • git diff <source_branch> <target_branch> //对比差异
  • git add <filename> //修改完冲突,需要add以标记合并成功

其他

  • gitk //开灯图形化git
  • git config color.ui true //彩色的 git 输出
  • git config format.pretty oneline //显示历史记录时,每个提交的信息只显示一行
  • git add -i //交互式添加文件到暂存区

相关文章

  • git 的使用

    有关git的使用总结一下,留着使用 git、svn区别 使用过程 svn基本使用过程 git基本使用过程 管理模式...

  • [Git使用] git基本使用

    GIT常用命令新建Git仓库,创建新文件夹 git init添加文件到git索引 git add

  • git的基本使用

    git的基本使用

  • 初识git,用git 上传项目到GitHub

    分享一些git基本指令,不喜勿喷! git的基本使用指令 git init 初始化git仓库 git add . ...

  • git 命令语法

    git 基本使用 git init // 初始化git仓库 git add . // git 添加 git co...

  • git远程仓库关联

    一.GitHub常用指令 git的基本使用指令:git init ...

  • Git 基本使用

    1.CentOS 7 安装Git 安装git所需要的库yum install curl-devel expat-d...

  • Git基本使用

    ps -ef | grep node | awk '{print $2}' | xargs kill -9git ...

  • Git基本使用

    1:先设置git配置文件 1.1 查看配置文件 1.2 设置对应用户名和邮箱 2:生成公钥和私钥 执行命令后需...

  • git 基本使用

    一、git全局设置 git全局配置修改 git config -e --global 进步全局配置文件,然后点击字...

网友评论

      本文标题:git的基本使用

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