pro git 读书笔记 1

Git 1 - Getting Started

Git 的特点

  • Git 存储每个版本的快照;其他 VCS(版本控制系统) 存储两个版本的变化之处
    • 好处参考 Git 分支章节
  • Git 几乎所有操作都是本地的;其他 VCS 需要远程服务器
    • 这是因为 Git 在本地磁盘上有项目的整个历史.好处有两点,其一,访问速度很快;其二,断网时同样可以使用,upload 时再联网即可。
  • Git 具有完整性
    • store 之前,先进行 SHA-1 哈希算法校验,将检验和(40位16进制数)与其联系,所以每次修改 Git 都能知道。在 Git 数据库中不是以文件名存储,而是以它内容的哈希值存储。
  • Git 一般只 Add 数据,而不删除;其他 VCS,你可能丢失你没有 commit的数据
    • 更多关于 Git 如何存储数据,怎样恢复看似丢失的数据,请看 Undoing Things

三种状态(重点)

  • committed:数据安全存入本地数据库
  • modified:你修改了数据,但没有 commit 到本地数据库
  • staged:你已经标记了 modified 文件到当前版本,进入下一个 commit 快照

这把我们引向 Git 项目的三个主要 section:

  • Git directory: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.
  • working directory: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
  • staging area:a file, generally contained in your Git directory, that stores information about what will go into your next commit. It’s sometimes referred to as the “index”, but it’s also common to refer to it as the staging area.

基本的 Git 工作流如下:

  1. You modify files in your working directory.
  2. You stage the files, adding snapshots of them to your 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.

If a particular version of a file is in the Git directory, it’s considered committed. If it’s modified but has been 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. In Chapter 2, you’ll learn more about these states and how you can either take advantage of them or skip the staged part entirely.

Git 安装及配置

安装 msysGit (略),之后进行配置,主要是设置用户名和邮箱。

Git 自带工具 git config, 可以存储在三处:

  1. /etc/gitconfigfile: Contains values for every user on the system and all their repositories. If you pass the option --systemto git config, it reads and writes from this file pecifically.
  2. ~/.gitconfigor ~/.config/git/configfile: Specific to your user.You can make Git read and write to this file specifically by passing the --globaloption.
  3. config file in the Git directory (that is, .git/config) of whatever repository you’re currently using: Specific to that single repository.

优先级递增,如.git/config 会覆盖 /etc/gitconfig.

On Windows systems, Git looks for the .gitconfigfile in the $HOMEdirectory (C:Users$USERfor most people). It also still looks for /etc/gitconfig, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.

原文地址:https://www.cnblogs.com/seven7seven/p/4123763.html