SlideShare ist ein Scribd-Unternehmen logo
1 von 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内部培训文档

Weitere ähnliche Inhalte

Was ist angesagt?

DevOps Days Kyiv 2019 -- Victoria Metrics // Artem Navoiev
DevOps Days Kyiv 2019 -- Victoria Metrics // Artem NavoievDevOps Days Kyiv 2019 -- Victoria Metrics // Artem Navoiev
DevOps Days Kyiv 2019 -- Victoria Metrics // Artem NavoievMykola Marzhan
 
Hive+Tez: A performance deep dive
Hive+Tez: A performance deep diveHive+Tez: A performance deep dive
Hive+Tez: A performance deep divet3rmin4t0r
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestI Goo Lee
 
Cephfs架构解读和测试分析
Cephfs架构解读和测试分析Cephfs架构解读和测试分析
Cephfs架构解读和测试分析Yang Guanjun
 
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High AvailabilityBest practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High AvailabilityColin Charles
 
Apache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTApache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTCarsten Ziegeler
 
Postgres Vision 2018: WAL: Everything You Want to Know
Postgres Vision 2018: WAL: Everything You Want to KnowPostgres Vision 2018: WAL: Everything You Want to Know
Postgres Vision 2018: WAL: Everything You Want to KnowEDB
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyDaniel Bimschas
 
High Concurrency Architecture at TIKI
High Concurrency Architecture at TIKIHigh Concurrency Architecture at TIKI
High Concurrency Architecture at TIKINghia Minh
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
 
Airflow presentation
Airflow presentationAirflow presentation
Airflow presentationIlias Okacha
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB FundamentalsMongoDB
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinStåle Deraas
 
Inno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code StructureInno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code StructureMySQLConference
 
OrientDB introduction - NoSQL
OrientDB introduction - NoSQLOrientDB introduction - NoSQL
OrientDB introduction - NoSQLLuca Garulli
 
Boomi Molecule Migration to the Cloud: Top 5 Strategies Revealed
Boomi Molecule Migration to the Cloud: Top 5 Strategies RevealedBoomi Molecule Migration to the Cloud: Top 5 Strategies Revealed
Boomi Molecule Migration to the Cloud: Top 5 Strategies RevealedKellton Tech Solutions Ltd
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialJean-François Gagné
 

Was ist angesagt? (20)

Redis basics
Redis basicsRedis basics
Redis basics
 
DevOps Days Kyiv 2019 -- Victoria Metrics // Artem Navoiev
DevOps Days Kyiv 2019 -- Victoria Metrics // Artem NavoievDevOps Days Kyiv 2019 -- Victoria Metrics // Artem Navoiev
DevOps Days Kyiv 2019 -- Victoria Metrics // Artem Navoiev
 
Hive+Tez: A performance deep dive
Hive+Tez: A performance deep diveHive+Tez: A performance deep dive
Hive+Tez: A performance deep dive
 
MySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software TestMySQL/MariaDB Proxy Software Test
MySQL/MariaDB Proxy Software Test
 
Cephfs架构解读和测试分析
Cephfs架构解读和测试分析Cephfs架构解读和测试分析
Cephfs架构解读和测试分析
 
Hadoop and OpenStack
Hadoop and OpenStackHadoop and OpenStack
Hadoop and OpenStack
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Best practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High AvailabilityBest practices for MySQL/MariaDB Server/Percona Server High Availability
Best practices for MySQL/MariaDB Server/Percona Server High Availability
 
Apache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and RESTApache Sling : JCR, OSGi, Scripting and REST
Apache Sling : JCR, OSGi, Scripting and REST
 
Postgres Vision 2018: WAL: Everything You Want to Know
Postgres Vision 2018: WAL: Everything You Want to KnowPostgres Vision 2018: WAL: Everything You Want to Know
Postgres Vision 2018: WAL: Everything You Want to Know
 
Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
High Concurrency Architecture at TIKI
High Concurrency Architecture at TIKIHigh Concurrency Architecture at TIKI
High Concurrency Architecture at TIKI
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
 
Airflow presentation
Airflow presentationAirflow presentation
Airflow presentation
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublin
 
Inno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code StructureInno Db Internals Inno Db File Formats And Source Code Structure
Inno Db Internals Inno Db File Formats And Source Code Structure
 
OrientDB introduction - NoSQL
OrientDB introduction - NoSQLOrientDB introduction - NoSQL
OrientDB introduction - NoSQL
 
Boomi Molecule Migration to the Cloud: Top 5 Strategies Revealed
Boomi Molecule Migration to the Cloud: Top 5 Strategies RevealedBoomi Molecule Migration to the Cloud: Top 5 Strategies Revealed
Boomi Molecule Migration to the Cloud: Top 5 Strategies Revealed
 
The Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication TutorialThe Full MySQL and MariaDB Parallel Replication Tutorial
The Full MySQL and MariaDB Parallel Replication Tutorial
 

Ähnlich wie 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
 

Ähnlich wie 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内部培训文档