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 进行版本控制》第三版

第 15 章 子模块 子模块

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

通常情况下,很多应用程序都依赖于 一个或一组实用程序库。在这种情况下,你会希望每个程序都在自己的 Git 仓库中开发、共享、分支和合并,因为这是逻辑上的分离单位,也可能是因为代码所有权的问题。

但这样划分应用程序会产生一个问题。每个应用程序都依赖于特定版本的共享库,你需要准确地跟踪哪个版本。如果有人不小心将共享库升级到了未经测试的版本,就可能会导致应用程序崩溃。此外,实用程序库并不完全是自己开发的;通常人们会对其进行调整,以添加自己应用程序所需的新功能。最终,他们希望与编写其他应用程序的所有人共享这些新功能;这就是实用程序库的作用

为了解决这个问题,通常会使用几种策略,包括进行部分签出、将依赖代码直接导入到项目中,甚至将依赖项目作为子文件夹复制到项目中。但这些都不是优雅的解决方案;事实上,有些人认为它们是 "黑客"。

Git 通过子模块解决了这个问题。子模块就是一个项目,它是 Git 仓库的一部分,但也独立存在于自己的源代码控制仓库中。Git 的机制是通过 gitlink 来显示对另一个 Git 仓库的直接引用。在本章中,我们将首先介绍如何使用 git 链接,然后提供几种使用子模块的技巧。最后,我们将讨论作为子模块替代方案的subtree 命令。

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