https://www.cnblogs.com/jager/p/6684637.html

四、git工作原理

这边文章介绍的不错 Git from the Bottom Up

六、git常用命令

  •   workspace: 本地工作目录
  •   index:缓存区域,临时保存本地改动
  •   local repository: 本地仓库
  •   remote repository:远程仓库

 

== git配置 ==
git config --list //查看当前git的配置,Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置) == 查看信息 ==
git log //查看提交记录
git status //查看修改状态
git diff //查看详细修改内容
git show //显示某次提交的内容
git branch //列出所有本地分支
git tag //列出所有tag
git reflog //显示当前分支的最近几次提交 == 新建代码库 ==
git init //在当前目录新建一个Git代码库
git init [project-name] //新建一个目录,将其初始化为Git代码库
git clone [url] //下载一个项目和它的整个代码历史 == 增加/删除 ==
git add [file1] [file2] ... //添加指定文件到暂存区
git add [dir] //添加指定目录到暂存区,包括子目录
git add . //添加当前目录的所有文件到暂存区
git rm [file1] [file2] ... //删除工作区文件,并且将这次删除放入暂存区
git mv [file-original] [file-renamed] //改名文件,并且将这个改名放入暂存区 == 代码提交 ==
git commit -m [message] //代码提交到本地仓库
git commit [file1] [file2] ... -m [message] //提交指定文件到本地仓库
git commit -a //提交工作区自上次commit之后的变化,直接到仓库区
git commit -v //提交时显示所有diff信息
git commit --amend -m [message] //使用一次新的commit,替代上一次提交,如果代码没有任何新变化,则用来改写上一次commit的提交信息 == 分支管理 ==
git branch -r //列出所有远程分支
git branch -a //列出所有本地分支和远程分支
git branch [branch-name] //新建一个分支,但依然停留在当前分支
git checkout -b [branch] //新建一个分支,并切换到该分支
git checkout [branch-name] //切换到指定分支,并更新工作区
git checkout - //切换到上一个分支
git merge [branch] //合并指定分支到当前分支(如master)
git branch -d [branch-name] //删除分支
git push origin --delete [branch-name] //删除远程分支
git branch -dr [remote/branch] //删除远程分支 == 远程同步 ==
git fetch [remote] //下载远程仓库的所有变动,到index
git pull //更新本地仓库至最新改动,到workspace
git remote -v //显示所有远程仓库
git remote show [remote] //显示某个远程仓库的信息
git remote add [shortname] [url] //增加一个新的远程仓库,并命名
git pull [remote] [branch] //取回远程仓库的变化,并与本地分支合并
git push origin master //推送至master分支
git push [remote] [branch] //上传本地指定分支到远程仓库
git push [remote] --force //强行推送当前分支到远程仓库,即使有冲突
git push [remote] --all //推送所有分支到远程仓库 == 撤销 ==
git reset [file] //重置暂存区的指定文件,与上一次commit保持一致,但工作区不变
git reset --hard //重置暂存区与工作区,与上一次commit保持一致
git checkout //从index恢复到workspace
git checkout . //恢复暂存区的所有文件到工作区
git checkout -- files //文件从index恢复到workspace
git checkout HEAD -- files //文件从local repository复制到workspace == 冲突解决 ==
git diff //对比workspace与index
git diff HEAD //对于workspace与最后一次commit
git diff <source_branch> <target_branch> //对比差异
git add <filename> //修改完冲突,需要add以标记合并成功

七、git使用流程规范【重要】

下面是ThoughtBot 的Git使用规范流程,推荐使用:

Create a local feature branch based off master.

git checkout master
git pull
git checkout -b <branch-name>

Rebase frequently to incorporate upstream changes.

git fetch origin
git rebase origin/master

Resolve conflicts. When feature is complete and tests pass, stage the changes.

git add --all

When you've staged the changes, commit them.

git status
git commit --verbose

Write a good commit message. Example format:

Present-tense summary under 50 characters

* More information about commit (under 72 characters).
* More information about commit (under 72 characters). http://project.management-system.com/ticket/123

If you've created more than one commit, use git rebase interactively to squash them into cohesive commits with good messages:

git rebase -i origin/master

Share your branch.

git push origin <branch-name>

Submit a GitHub pull request.

Ask for a code review in the project's chat room.

总结大致如下:

  •   新建分支
  •   提交分支
  •   撰写commit信息
  •   与主干同步
  •   合并commit
  •   推送到远程仓库
  •   发出pull request,请求别人进行代码review

【Git123】Git的更多相关文章

  1. 【经验之谈】Git使用之TortoiseGit配置VS详解

    前言 上一篇<[经验之谈]Git使用之Windows环境下配置>: 安装 配置和使用 后记 关于vs中使用git网上的教程大家也可以找到,我当时配置的时候也是按照网上找的教程一步一步来的, ...

  2. 【转】Git如何Check Out出指定文件或者文件夹

    [转]Git如何Check Out出指定文件或者文件夹http://www.handaoliang.com/a/20140506/195406.html 在进行项目开发的时候,有时候会有这样的需求那就 ...

  3. 【转】Git超实用总结,再也不怕记忆力不好了

    [转]Git超实用总结,再也不怕记忆力不好了 欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯工蜂发表于云+社区专栏 Git 是什么? Git 是一个分布式的代码管理容器,本地和 ...

  4. (转)【经验之谈】Git使用之TortoiseGit配置VS详解

    原文地址:http://www.cnblogs.com/xishuai/p/3590705.html 前言 上一篇<[经验之谈]Git使用之Windows环境下配置>: 安装 配置和使用 ...

  5. 【译文】Git merge 和 Git rebase比较

    [译文]Git merge 和 Git rebase比较 原创: 胡江华 胡同学和朋友们的成长日记 2017-03-22 git rebase 这个命令经常被人认为是一种Git巫术,初学者应该避而远之 ...

  6. 【61】git项目实战的步骤总结

    1.新建分支的步骤 git pull git checkout -b 分支号(task的后面的代号) 2.提交代码到远程仓库的步骤 git add . git commit -m "分支号+ ...

  7. 【原创】Git删除暂存区或版本库中的文件

    0 基础     我们知道Git有三大区(工作区.暂存区.版本库)以及几个状态(untracked.unstaged.uncommited),下面只是简述下Git的大概工作流程,详细的可以参见本博客的 ...

  8. 【转】Git 安装和使用教程

    git 提交 全部文件 git add .  git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件.注意 -A 选项后面还有一个 ...

  9. 【git2】git+码云+webStrom

    在[git1]中介绍了Git的安装.webstrom配置Git和GitHub.GitHub项目上传下载的方法. 这篇将一下在[git1]步骤(一)基础上webstorm配置码云 实现项目的上传下载. ...

随机推荐

  1. Java学习第二篇 — 时间类的使用

    package DateTest; import java.util.Date; public class Date1 { public static void main(String[] args) ...

  2. 杭电acm习题分类

    专注于C语言编程 C Programming Practice Problems (Programming Challenges) 杭电ACM题目分类 基础题:1000.1001.1004.1005. ...

  3. 【学习笔记】--- 老男孩学Python,day4 编码,数据类型,字符串方法

    今日主要内容 1. 编码 1. 最早的计算机编码是ASCII. 美国人创建的. 包含了英文字母(大写字母, 小写字母). 数字, 标点等特殊字符!@#$% 128个码位 2**7 在此基础上加了一位 ...

  4. html前端学习

    html : 1.相当于没有穿衣服的人,一套浏览器认识的规则, 2.开发者: 学习html规则 开发后台程序: -写html文件(充当模板) -数据库获取数据,然后替换到html文件的指定位置(web ...

  5. 【代码笔记】iOS-4个可以单独点击的button

    一,效果图. 二,工程图. 三,代码. ViewController.m #import "ViewController.h" @interface ViewController ...

  6. @Schedul 中cron的命名规则

    @Schedul注解的定时任务详解 1.springboot集成schedule由于Spring Schedule包含在spring-boot-starter基础模块中了,所有不需要增加额外的依赖. ...

  7. ss 重新设置 端口的方法 记录

    1. 选择 ssh 进行远程登入: ssh root@服务器ip -p 端口, 事例如:ssh root@176.122.134.96 -p 28202 2. ls 展示 当前目录下的文件,看到有 s ...

  8. SD从零开始09-10

    SD从零开始9 数据流(Data Flow) 根据参考创建Create with reference 可以参考之前的凭证来创建销售凭证,可以在初始画面,也可以在凭证处理过程中,通过uniform. d ...

  9. TensorFlow数据读取方式:Dataset API

    英文详细版参考:https://www.cnblogs.com/jins-note/p/10243716.html Dataset API是TensorFlow 1.3版本中引入的一个新的模块,主要服 ...

  10. android:首页点击返回键,两秒内再次点击退出系统

    //记录用户首次点击返回键的时间 private long firstTime = 0; /** * 通过监听keyUp 实现双击返回键退出程序 * @param keyCode * @param e ...