Git入门

Git入门

简介

Git是一个免费开源的分布式版本控制系统,用于管理项目的方方面面,能够高速、高效地用于从小项目到非常大的项目。

工作流程及术语

  • 工作空间(workspace):当前项目文件夹
  • 索引(index):工作空间索引
  • 本地仓库(localrepo):本地保存历史版本内容的数据库
  • 远程仓库(remoterepo):远程保存历史版本内容的数据库
Created with Raphaël 2.1.0 workspace workspace index index localrepo localrepo remoterepo remoterepo add commit -m commit -am push pull fetch checkout HEAD checkout diff HEAD diff

本地工作流演示

  • 设置个人身份
git config --help
git config --global user.name "<user name>"
git config --global user.email <email>
  • 初始化本地仓库
[titi@mine test]$ git init
Initialized empty Git repository in /home/titi/test/.git/
  • 新建文件
[titi@mine test]$ echo 1 > text
[titi@mine test]$ git status -s
?? text
  • 添加至索引
[titi@mine test]$ git add text
[titi@mine test]$ git status -s
A  text
  • 添加至本地仓库
[titi@mine test]$ git commit -m "The first commit"
[master (root-commit) 9513892] The first commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 text
[titi@mine test]$ git log
commit 9513892bd948ebaa7c12cb0c6c5d4a7814a77433
Author: Dazhi Jiang <ejdazhi@163.com>
Date:   Sun Oct 30 15:23:32 2016 +0800

    The first commit
  • 直接添加至本地仓库
[titi@mine test]$ echo 111 > text
[titi@mine test]$ git status -s
 M text
[titi@mine test]$ git commit -am 'the second commit'
  • 更改文件并添加至索引
[titi@mine test]$ echo 222 >> text
[titi@mine test]$ cat text
111
222
[titi@mine test]$ git add text
  • 再次更改文件
[titi@mine test]$ echo 333 >> text
[titi@mine test]$ cat text
111
222
333
  • 本地仓库与工作空间差异
[titi@mine test]$ git diff HEAD
diff --git a/text b/text
index 58c9bdf..641d574 100644
--- a/text
+++ b/text
@@ -1 +1,3 @@
 111
+222
+333
  • 索引与工作空间差异
[titi@mine test]$ git diff
diff --git a/text b/text
index a30a52a..641d574 100644
--- a/text
+++ b/text
@@ -1,2 +1,3 @@
 111
 222
+333
  • 重置工作空间至索引
[titi@mine test]$ git checkout text
[titi@mine test]$ cat text
111
222
  • 重置工作空间至本地仓库最后版本
[titi@mine test]$ git checkout HEAD text
[titi@mine test]$ cat text
111
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值