1.1 Getting Started - About Version Control
What is a Version Control System(VCS)?
a system that records changes to a file or set of files over time so that you can recall specific versions later.
- to revert files back to a previous state,
- revert the entire project back to a previous state,
- compare changes over time,
- see who last modified something that might be causing a problem,
- who introduced an issue and when,
- and more
历代VCS | 实例 | 特 点 |
Local VCS | RCS(Mac OS X) | a simple database that kept all the changes to files under revision control Downside:whenever you have the entire history of the project in a single place, you risk losing everything. |
Centralized VCS | CVS, Subversion, and Perforce | have a single server that contains all the versioned files, and a number of clients that check out files from that central place. Downside:the single point of failure that the centralized server represents;whenever you have the entire history of the project in a single place, you risk losing everything. |
Distributed VCS | Git, Mercurial, Bazaar or Darcs | clients don’t just check out the latest snapshot of the files: they fully mirror the repository. Every clone is really a full backup of all the data.you can collaborate with different groups of people in different ways simultaneously within the same project |
1.2 Getting Started - A Short History of Git
1.3 Getting Started - Git Basics
Git: Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. Git thinks about its data more like a stream of snapshots.Contrast: other VCSs think of the information they keep as a set of files and the changes made to each file over time.
Nearly Every Operation Is Local
the gods of speed,doesn’t need to go out to the server to get the history and display it for you, very little you can’t do if you’re offline or off VPNGit Has Integrity
Everything in Git is check-summed before it is stored and is then referred to by that checksum. SHA-1 hash,40-character string composed of hexadecimal characters (0–9 and a–f)
Git Generally Only Adds Data
after you commit a snapshot into Git, it is very difficult to loseThe Three States
Git has three main states that your files can reside in:committed, the data is safely stored in your local database
modified, have changed the file but have not committed it to your database yet.
staged. you have marked a modified file in its current version to go into your next commit snapshot
three main sections of a Git project:
the Git directory, where Git stores the metadata and object database for your project
the working tree, a single checkout of one version of the project. placed on disk for you to use or modify.
the staging area. a file, generally contained in your Git directory, that stores information about what will go into your next commit.
If a particular version of a file is in the Git directory, it’s considered committed.
If it has been modified and was added to the staging area, it is staged.
And if it was changed since it was checked out but has not been staged, it is modified.
1.4 Getting Started - The Command Line
the command line is the only place you can run all Git commands
1.5 Getting Started - Installing Git
sets up solid credential caching and sane CRLF settings.You can download this from the GitHub for Windows website, at http://windows.github.com.
1.6 Getting Started - First-Time Git Setup
配置工具 git config
<非Windows>
三个层次配置,配置项的位置:
系统级 git config --system /etc/gitconfig file
用户级 git config --global ~/.config/git/config
目录级 config file in the git directory
下层配置override上层配置
<Windows> (不知道哪个文件是哪个层级的了)
$Home 下的.gitconfig文件
git安装目录下的/etc/gitconfig
C:\ProgramData\Git\config --his config file can only be changed by git config -f <file>
as an admin.
Your Identity
用git config --global user.name "xxxxxxx" 和 git config --global user.email "xxxxxxx" 设定全局ID可以为具体项目单独设定id,在项目下,不用--global
Your Editor
core.editor列出配置项
git config --list
查看单个配置项
git config 配置项名
1.7 Getting Started - Getting Help
命令1: $git help <verb>
命令2: $git <verb> --help
命令3: $man git-<verb>
you can try the #git
or #github
channel on the Freenode IRC server (irc.freenode.net). (打不开)
2.1 Git Basics - Getting a Git Repository
Getting a Git Repository
Method 1: Initializing a Repository in an Existing Directory
cd 进入需要建立git repository的目录$ git init
在此目录下会生成名为.git的一个文件夹--一个git repository框架
git add 添加要追踪的文件
// 遇到 "LF will be replaced by CRLF " 说明相关文件是以LF结尾的。
什么是LF?什么是CRLF ?Git中的CRLF和LF 两者区别 StackOverFlow 相关问题
// 配置项 git config core.autocrlf 是True
git commit 提交
Method 2: Cloning an Existing Repository
"clone" and not "checkout". 区别很大,前者下载了所有历史数据,后者只下了当前的工作数据。
命令: $git clone [url] (重命名库名)
2.2 Git Basics - Recording Changes to the Repository