Skip to Content
《使用 Git 进行版本控制》第三版
book

《使用 Git 进行版本控制》第三版

by Prem Kumar Ponuthorai, Jon Loeliger
May 2025
Beginner to intermediate
548 pages
7h 40m
Chinese
O'Reilly Media, Inc.
Content preview from 《使用 Git 进行版本控制》第三版

第 1 章 Git 简介

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

简而言之,Git 是一个内容跟踪器。鉴于这一概念,Git 与大多数版本控制系统有着共同的原则。然而,Git 的独特之处在于它是一个分布式的版本控制系统,这也是 Git 在当今众多工具中独树一帜的原因。这意味着 Git 速度快、可扩展性强,拥有丰富的命令集,既能进行高级操作,也能进行低级操作,并针对本地操作进行了优化。

在本章中,你将学习到 Git 的基本原理、特点和基本的git 命令,并获得一些创建和添加修改到仓库的快速指导。

我们强烈建议你花点时间掌握这里解释的重要概念。这些主题是 Git 的基石,将帮助你理解日常工作中管理 Git 仓库的中高级技术。当我们在第二部分 "Git 基础"、 第三部分 "中级技巧 "第四部分 "高级技巧 " 分解 Git 的内部运作时,这些基础概念也将帮助你提升学习效率。

Git 组件

在深入了解git 命令世界之前, ,让我们退后一步,直观地了解一下组成 Git 生态系统的各个组件的概况。图 1-1展示了这些组件是如何协同工作的。

Git GUI 工具是 Git 命令行的前端,有些工具还有与流行的 Git 托管平台集成的扩展。Git 客户端工具大多在本地版本库中运行。

vcg3 0101
图 1-1. Git 组件概览

使用 Git 时,典型的设置包括 Git 服务器和 Git 客户端。你也可以不使用服务器,但这将增加在协作设置中共享修订变更时维护和管理版本库的复杂性,并使一致性变得更加困难(我们将在第 11 章再次讨论这个问题)。Git 服务器和客户端的工作原理如下:

Git 服务器

有了 Git 服务器,您就能更轻松地开展协作, ,因为它能确保为您要处理的仓库提供一个集中可靠的真实来源。Git 服务器也是存储远程 Git 仓库的地方;按照惯例,该仓库拥有项目最新、最稳定的源代码。你可以选择安装和配置自己的 Git 服务器,也可以放弃这些开销,选择将 Git 仓库托管在可靠的第三方托管网站上,如 GitHub、GitLab 和 Bitbucket。

Git 客户端

Git 客户端与本地仓库交互,,你能通过 Git 命令行或 Git 用户界面工具与 Git 客户端交互。安装并配置好 Git 客户端后,你就能访问远程仓库,在本地仓库副本上工作,并将修改推送回 Git 服务器。如果您是 Git 的新手,我们建议您先从 Git 命令行开始;熟悉日常操作所需的常用git 命令子集,然后再逐步过渡到您所选择的 Git GUI 工具。

采用这种方法的原因是,在某种程度上,Git 用户界面工具往往会提供一些术语,代表一种可能不属于 Git 标准命令的预期结果。例如,Git 工具有一个名为sync 的选项,它掩盖了两个或多个git 命令的底层链,以实现所需的结果。如果出于某种原因在命令行中输入sync 子命令,可能会得到如下令人困惑的输出结果:

$ git sync

git: 'sync' is not a git command. See 'git --help'.

The most similar command is
       svn
备注

git sync 不是有效的 子命令。要确保本地版本库工作副本与远程 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

学习 GitHub Actions

学习 GitHub Actions

Brent Laster
《Kubernetes 最佳实践》第二版

《Kubernetes 最佳实践》第二版

Brendan Burns, Eddie Villalba, Dave Strebel, Lachlan Evenson
GraphQL 学习指南

GraphQL 学习指南

Eve Porcello, Alex Banks

Publisher Resources

ISBN: 9798341657922