SlideShare a Scribd company logo
1 of 32
superwen
 Linux 内核开源项目有着为数众广的参与者。一开始
  整个项目组BitKeeper 来管理和维护代码。 2005 年,
  BitKeeper不再能免费使用,这就迫使 Linux 开源社区
  开发一套属于自己的版本控制系统。
 自诞生于 2005 年以来,Git 日臻成熟完善,它的速度
  飞快,极其适合管理大项目,它还有着令人难以置信
  的非线性分支管理系统,可以应付各种复杂的项目开
  发需求。
 直接记录快照,而非差异比较。
 近乎所有操作都是本地执行
 时刻保持数据完整性
 多数操作仅添加数据
 文件的三种状态-已修改(modified)、已暂存
 (staged)和已提交(committed)
 本地建立版本库
 本地版本控制
 多主机异地协同工作
 重写提交说明
 有后悔药可以吃
 更好用的提交列表
 更好的差异比较。
 更完善的分支系统
 代理SVN提交实现移动式办公
 无处不在的分页器
 速度快
 使用包安装,以centos为例
  $ yum install git
  $ yum install git-svn git-email git-gui gitk
 使用源代码安装
  从官网下载源码 http://git-scm.com
   $ tar –jxvf git-version.tar.bz2
   $ cd git-version
   $ make prefix=/usr/local all
   $ sudo make install prefix=/usr/local
 通过Cygwin安装(不建议)
  http://www.cygwin.com
 通过msysGit
  http://code.google.com/p/msysgit
  完成安装之后,就可以使用命令行的 git 工具(已经
  自带了 ssh 客户端)了,另外还有一个图形界面的 Git
  项目管理工具。
 可视化工具TortoiseGit
  http://code.google.com/p/ tortoisegit
#查看版本
$ git --version
#配置
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
//--system 系统配置
//--global 该用户的全局配置
#查看配置信息
$ git config --list
$ git config user.name
#获取帮助,任意一个都可以
$ git help config
$ git config --help
$ man git-config
#在工作目录中初始化新仓库
$ cd myproject
$ git init
#从现有仓库克隆,克隆完整数据,包括版本信息
$ git clone git://github.com/schacon/grit.git
$ git clone git://github.com/schacon/grit.git mygrit
#检查当前文件状态
$ git status
#跟踪新文件
$ git add *.c
#将文件添加到暂缓区,每次修改之后都需要将文件放到暂缓区去
$ git add *.c
#忽略某些文件
#修改 .gitignore
   *.a    # 忽略所有 .a 结尾的文件
   !lib.a # 但 lib.a 除外
   /TODO # 仅仅忽略项目根目录下的 TODO 文件,不包括
   subdir/TODO
   build/ # 忽略 build/ 目录下的所有文件
   doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
#查看尚未暂存的文件更新了哪些部分
$ git diff
#查看暂存区文件和上次提交的快照之间的差异
$ git diff --cached
#提交更新
#每次准备提交前,先用 git status 看下,是不是都已暂
#存起来了,然后再运行提交命令
$ git commit
$ git commit -m 'initial project version'
#跳过使用暂存区域
$ git commit -a
#移除文件
$ git rm grit.gemspec
#移除已经修改的文件
$ git rm grit.gemspec-f
#仅仅从暂缓区移除
$ git rm grit.gemspec
#移除文件
$ git rm grit.gemspec
#移除已经修改的文件
$ git rm grit.gemspec-f
#仅仅从暂缓区移除
$ git rm grit.gemspec

#移动文件
$ git mv file_from file_to
#查看提交历史
$ git log
-p 展开显示每次提交的内容差异
-n 则仅显示最近的n次更新
--stat,仅显示简要的增改行数统计
--pretty=format:"%h - %an, %ar : %s"
#修改最后一次提交
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit –amend
#上面的三条命令最终只是产生一个提交.

#取消已经暂存的文件
$ git reset HEAD benchmarks.rb
#取消对文件的修改
$ git checkout -- benchmarks.rb
#查看当前的远程库
$ git remote
#显示对应的克隆地址(origin 为默认的远程库名称)
$ git remote –v

#添加远程仓库
$ git remote add pb
  git://github.com/paulboone/ticgit.git
#从远程仓库抓取数据
#fetch 命令只是将远端的数据拉到本地仓库,并不自动
  合并到当前工作分支
$ git fetch [remote-name]

#推送数据到远程仓库
$ git push origin master
#查看远程仓库信息
$ git remote show origin

#远程仓库的重命名
$ git remote rename pb paul
#远程仓库的删除
$ git remote rm paul
#列显已有的标签
$ git tag
#列出符合条件的标签
$ git tag -l 'v1.4.2.*'
#新建标签
#标签有两种类型:轻量级的(lightweight)和含附注
  的(annotated)
#创建一个轻量级标签
$ git tag v1.4-lw
#创建一个含附注类型的标签非常简单
$ git tag -a v1.4 -m 'my version 1.4'
#分享标签
#默认情况下,git push 不会把标签传送到远端服务器
$ git push origin v1.5
#一次推送所有本地新增的标签
$ git push origin --tags
#自动完成
#Windows 上安装了 msysGit,默认已经配好了这个自
  动完成脚本。
#Linux 上
$ cp {$GitHome}contrib/completion/git-
  completion.bash /etc/bash_completion.d/
#Git 命令别名
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.last 'log -1 HEAD'
#创建分支
$ git branch testing
#切换到分支
$ git checkout testing
#创建并切换到分支
$ git checkout -b testing
#与当前分支合并
$ git merge testing
#合并时难免有冲突
#调用图形化工具解决冲突
$ git mergetool

#删除分支(不能删除一个未合并的分支)
$ git branch -d testing
#强制删除一个分支
$ git branch -D testing
#查看分支
$ git branch
#查看分支最后一次提交的信息
$ git branch -v
#查看已经合并|尚未合并的分支
$ git branch --merged|no-merged
#同步远程服务器上的数据到本地
$ git fetch origin

#推送本地分支
$ git push origin serverfix
#推送本地分支serverfix为origin的awesomebranch分支
$ git push origin serverfix:awesomebranch

#删除远程分支
$ git push origin:serverfix
Git内部培训文档

More Related Content

What's hot

Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash CourseNilay Binjola
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction TutorialThomas Rausch
 
Formation M2i - TikTok, pourquoi y lancer une campagne ?
Formation M2i - TikTok, pourquoi y lancer une campagne ?Formation M2i - TikTok, pourquoi y lancer une campagne ?
Formation M2i - TikTok, pourquoi y lancer une campagne ?M2i Formation
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewRueful Robin
 
GitHub - Présentation
GitHub - PrésentationGitHub - Présentation
GitHub - PrésentationDavid RIEHL
 
Recommandation stratégique - Fullscreens - ISCOM Paris
Recommandation stratégique - Fullscreens - ISCOM Paris Recommandation stratégique - Fullscreens - ISCOM Paris
Recommandation stratégique - Fullscreens - ISCOM Paris Basile Viault
 
Treinamento git - Papos RBSDev
Treinamento git - Papos RBSDevTreinamento git - Papos RBSDev
Treinamento git - Papos RBSDevHélio Medeiros
 
Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)Valerio Radice
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrJohn Allspaw
 
#SitBERN modern abap development with abapgit
#SitBERN modern abap development with abapgit#SitBERN modern abap development with abapgit
#SitBERN modern abap development with abapgitChristian Günter
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitE Carter
 
Presentation linux on power
Presentation   linux on powerPresentation   linux on power
Presentation linux on powersolarisyougood
 

What's hot (20)

Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git basics
Git basicsGit basics
Git basics
 
Git (実践入門編)
Git (実践入門編)Git (実践入門編)
Git (実践入門編)
 
Git Introduction Tutorial
Git Introduction TutorialGit Introduction Tutorial
Git Introduction Tutorial
 
Introducing GitLab
Introducing GitLabIntroducing GitLab
Introducing GitLab
 
Formation M2i - TikTok, pourquoi y lancer une campagne ?
Formation M2i - TikTok, pourquoi y lancer une campagne ?Formation M2i - TikTok, pourquoi y lancer une campagne ?
Formation M2i - TikTok, pourquoi y lancer une campagne ?
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
GitHub - Présentation
GitHub - PrésentationGitHub - Présentation
GitHub - Présentation
 
Recommandation stratégique - Fullscreens - ISCOM Paris
Recommandation stratégique - Fullscreens - ISCOM Paris Recommandation stratégique - Fullscreens - ISCOM Paris
Recommandation stratégique - Fullscreens - ISCOM Paris
 
Treinamento git - Papos RBSDev
Treinamento git - Papos RBSDevTreinamento git - Papos RBSDev
Treinamento git - Papos RBSDev
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
 
Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)
 
Git 版本控制 (使用教學)
Git 版本控制 (使用教學)Git 版本控制 (使用教學)
Git 版本控制 (使用教學)
 
Dev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and FlickrDev and Ops Collaboration and Awareness at Etsy and Flickr
Dev and Ops Collaboration and Awareness at Etsy and Flickr
 
#SitBERN modern abap development with abapgit
#SitBERN modern abap development with abapgit#SitBERN modern abap development with abapgit
#SitBERN modern abap development with abapgit
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Presentation linux on power
Presentation   linux on powerPresentation   linux on power
Presentation linux on power
 
Source control
Source controlSource control
Source control
 

Similar to Git内部培训文档

Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshellNelson Tai
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence TutorialHo Kim
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹Max Ma
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹PingLun Liao
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)flylon
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub維佋 唐
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607Charles Tang
 
Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)Hsin-lin Cheng
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git工程師必備第一工具 - Git
工程師必備第一工具 - GitAlan Tsai
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍medcl
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgitRhythm Sun
 
Git+使用教程
Git+使用教程Git+使用教程
Git+使用教程gemron
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包Chen-Ming Yang
 
Git and git hub
Git and git hubGit and git hub
Git and git hub唯 李
 
Git使用入门
Git使用入门Git使用入门
Git使用入门dpf2e
 

Similar to Git内部培训文档 (20)

Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git Essence Tutorial
Git Essence TutorialGit Essence Tutorial
Git Essence Tutorial
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
 
Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)Git 超簡單學習懶人包(軟體程式版本控管系統)
Git 超簡單學習懶人包(軟體程式版本控管系統)
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
Git教學
Git教學Git教學
Git教學
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub
 
Git原理与实战 201607
Git原理与实战 201607Git原理与实战 201607
Git原理与实战 201607
 
Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)Git 簡介(古時候的簡報備份)
Git 簡介(古時候的簡報備份)
 
Git 教學
Git 教學Git 教學
Git 教學
 
工程師必備第一工具 - Git
工程師必備第一工具 - Git工程師必備第一工具 - Git
工程師必備第一工具 - Git
 
Git 使用介绍
Git 使用介绍Git 使用介绍
Git 使用介绍
 
First meetingwithgit
First meetingwithgitFirst meetingwithgit
First meetingwithgit
 
Git+使用教程
Git+使用教程Git+使用教程
Git+使用教程
 
20170510 git 懶人包
20170510 git 懶人包20170510 git 懶人包
20170510 git 懶人包
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git使用入门
Git使用入门Git使用入门
Git使用入门
 

Git内部培训文档