Getting Started

About Version Control

  Local Version Control Systems

  Centralized Version Control Systems

  Distributed Version Control Systems

A Short History of Git

  2005, Linus Torvalds, Linux Community

  goals of Git:

  • Speed

  • Simple design

  • Strong support for non-linear development (thousands of parallel branches)

  • Fully distributed

  • Able to handle large projects like the Linux kernel efficiently (speed and data size)

Git Basics

  Snapshots, not differences

  With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.

  This makes Git more like a mini filesystem with some incredibly powerful tools built on top of it, rather than simply a VCS.

  Nearly every operations is local

  Git has integrity

  Everything in Git is check-summed before it is stored and is then referred to by that checksum. This means it’s impossible to change the contents of any file or directory without Git knowing about it.

  The mechanism that Git uses for this checksumming is called a SHA-1 hash.

  In fact, Git stores everything in its database not by file name but by the hash value of its contents.

  Git generally only add datas

  When you do actions in Git, nearly all of them only add data to the Git database. It is hard to get the system to do anything that is not undoable or to make it erase data in any way.

  The three states

  Git has three main states that your files can reside in: committedmodified, and staged

  • Committed means that the data is safely stored in your local database.

  • Modified means that you have changed the file but have not committed it to your database yet.

  • Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

  This leads us to the three main sections of a Git project: the Git directory, the working tree, and the staging area.

  The Git directory is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

  The working tree is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify.

  The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. Its technical name in Git parlance is the “index”, but the phrase “staging area” works just as well.

  The basic Git workflow goes something like this:

  1. You modify files in your working tree.

  2. You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.

  3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

The Command Line

Installing Git

  Linux:

  on Federo, RHEL, CentOS

$ sudo dnf install git-all

  on Debian, Ubuntu

$ sudo apt install git-all

  Mac OS:

$ git --version

  Windows:

  http://git-scm.com/download/win

  From source:

  ...

First-Time Git Setup

  Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:

  /etc/gitconfig file

  ~/.gitconfig or ~/.config/git/config file

  config file in the Git directory (that is, .git/config) of whatever repository you’re currently using

  Your identity

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

  Your Editor

$ git config --global core.editor emacs

  On a Windows system, if you want to use a different text editor, you must specify the full path to its executable file.

$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession"
$ git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -nosession"

  Check your settings

$ git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...

  You can also check what Git thinks a specific key’s value is by typing git config <key>:

$ git config user.name
John Doe

Getting Help

$ git help <verb>
$ man git-<verb>

  Example:

$ git help config

  in additon:

$ git add -h
usage: git add [<options>] [--] <pathspec>... -n, --dry-run dry run
-v, --verbose be verbose -i, --interactive interactive picking
-p, --patch select hunks interactively
-e, --edit edit current diff and apply
-f, --force allow adding otherwise ignored files
-u, --update update tracked files
-N, --intent-to-add record only the fact that the path will be added later
-A, --all add changes from all tracked and untracked files
--ignore-removal ignore paths removed in the working tree (same as --no-all)
--refresh don't add, only refresh the index
--ignore-errors just skip files which cannot be added because of errors
--ignore-missing check if - even missing - files are ignored in dry run
--chmod <(+/-)x> override the executable bit of the listed files
$ git add --help

Summary

Pro Git - 笔记1的更多相关文章

  1. Pro Git - 笔记3

    Git Branching Branches in a Nutshell Branches in a Nutshell let’s assume that you have a directory c ...

  2. Pro Git - 笔记2

    Git Basics Getting a Git Repository Initializing a Repository in an Existing Directory For Linux: $ ...

  3. Pro Git 第一章 起步 读书笔记

    Pro Git 笔记 第1章 起步 1.文件的三种状态. 已提交:文件已经保存在本地数据库中了.(commit) 已修改:修改了某个文件,但还没有提交保存.(vim) 已暂存:已经把已修改的文件放在下 ...

  4. 《Pro Git》笔记3:分支基本操作

    <Pro Git>笔记3:Git分支基本操作 分支使多线开发和合并非常容易.Git的分支就是一个指向提交对象的可变指针,极其轻量.Git的默认分支为master. 1.Git数据存储结构和 ...

  5. 【Tools】Pro Git 一二章读书笔记

    记得知乎以前有个问题说:如果用一天的时间学习一门技能,选什么好?里面有个说学会Git是个很不错选择,今天就抽时间感受下Git的魅力吧.   Pro Git (Scott Chacon) 读书笔记:   ...

  6. Git Pro读书笔记

    本文为Git Pro读书笔记,所有内容均来自Git Pro 1 Git基础 1.1 记录每次更新到仓库 在Git里,文件有4种状态,modified, staged, commited, 还有一种状态 ...

  7. [Git00] Pro Git 一二章读书笔记

    记得知乎以前有个问题说:如果用一天的时间学习一门技能,选什么好?里面有个说学会Git是个很不错选择,今天就抽时间感受下Git的魅力吧.   Pro Git (Scott Chacon) 读书笔记:   ...

  8. Pro Git 学习笔记

    Pro Git 学习笔记 文档地址:Pro Git原文地址:PRO GIT 学习笔记 git常见命令 1.Git起步 初次运行Git前的配置 用户信息 git config --global user ...

  9. 《Pro Git》阅读随想

    之前做版本管理,我使用最多的是SVN,而且也只是在用一些最常用的操作.最近公司里很多项目都开始上Git,借这个机会,我计划好好学习一下Git的操作和原理,以及蕴含在其中的设计思想.同事推荐了一本< ...

随机推荐

  1. 优雅的QSignleton (三) 通过属性器实现Singleton

    接下来介绍,不通过继承的方式实现单例模式.大家都出去嗨了,而我却在家码代码... 代码如下: MonoSingletonProperty.cs namespace QFramework.Example ...

  2. flask中的request

    1.request是什么? 简单来说,它就是flask的封装的一个对象,这个对象包含着前端请求所带的所有信息.既然说它是一个对象,那么它肯定是有一些熟悉,和方法的,下面就来介绍下request里的熟悉 ...

  3. Vue+Electron实现简单桌面应用

    之前一直使用C#编写桌面应用,也顺带写一些Web端应用.最近在看node时发现常用的vscode是用electron编写的,一种想吃螃蟹的念头就涌了上来. 在网上找了找electron的资料,也研究了 ...

  4. Delphi 版FindWindow 和 FindWindowEx 的语法和用法

    FindWindow(lpClassName,        {窗口的类名}lpWindowName: PChar {窗口的标题}): HWND;              {返回窗口的句柄; 失败返 ...

  5. CentOS7版本基础使用

    第1章 CentOS7的使用 1.1 为什么要使用CentOS7版本 CentOS7是在CentOS6基础上发布的新版本,与之前的版本相比,主要的更新包括: 1.内核更新到3.10.0 2.支持Lin ...

  6. dedecms添加/编辑文章如何把附加选项去掉默认勾选状态

    1.去掉添加时默认勾选状态. 在 系统->系统基本参数->其它选项 中,如图中的三个选项选择否即可. 设置完后可以看到添加时已经默认不勾选,但是编辑文章时还是默认勾选状态. 2.去掉编辑时 ...

  7. MySQL版本详解

    一.版本说明 1.1.MySQL相关连接 MySQL官网:https://www.mysql.com/ MySQL下载:https://dev.mysql.com/downloads/mirrors/ ...

  8. mongodb的windows系统下安装

    先下载安装包,地址有下面两个,按需选择吧. https://www.mongodb.com/download-center/v2/community https://www.mongodb.org/d ...

  9. mysql帐号不允许从远程登陆

    默认情况下,mysql帐号不允许从远程登陆,只能在localhost登录.本文提供了二种方法设置mysql可以通过远程主机进行连接. 一.改表法 在localhost登入mysql后,更改 “mysq ...

  10. scala成长之路(4)compaion object——伴生对象的使用

    虽然java一直声称自己是完全面向对象的语言,但一直以来都被很多人所质疑,其中java的静态成员函数就是主要的“罪魁祸首”.由于java中保留了静态方法的调用,导致其编程模式依然有过程式编程的可能,尤 ...