Git用户介绍及其说明书~.doc

上传人:小** 文档编号:630215 上传时间:2019-04-22 格式:DOC 页数:143 大小:278.68KB
返回 下载 相关 举报
Git用户介绍及其说明书~.doc_第1页
第1页 / 共143页
Git用户介绍及其说明书~.doc_第2页
第2页 / 共143页
点击查看更多>>
资源描述

《Git用户介绍及其说明书~.doc》由会员分享,可在线阅读,更多相关《Git用户介绍及其说明书~.doc(143页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、-_Git 用户手册(用户手册(1.5.3 及后续版及后续版 本适用)本适用) 翻译: 罗峥嵘罗峥嵘 (Robin Steven) 英文版本: http:/www.kernel.org/pub/software/scm/git/docs/user- manual.html Contents1.Preface 前言 2.Chapter 1. Repositories and Branches 第一章. 版本库与分支 1.How to get a git repository 如何获取一个版本库 2.How to check out a different version of a project

2、 如何提取项目的不同版本 3.Understanding History: Commits 理解历史: 交付 1.Understanding history: commits, parents, and reachability 交付,父交付与可及性 2.Understanding history: History diagrams 历史沿革示图 3.Understanding history: What is a branch? 理解历史:什么是分支 4.Manipulating branches 操作分支 5.Examining an old version without creatin

3、g a new branch 不通过创建新分支来调查旧版本 6.Examining branches from a remote repository 调查远程版本库上的分支 7.Naming branches, tags, and other references 命名分支,标签,与其他引用 8.Updating a repository with git-fetch 用 git fetch 更新版本库 9.Fetching branches from other repositories 获取其他版本库的分支 3.Chapter 2. Exploring git history 第二章.

4、检索 git 历史 1.How to use bisect to find a regression 如何用平分来定位撤退 2.Naming commits 交付的称谓 3.Creating tags 创建标签 4.Browsing revisions 浏览修订 5.Generating diffs 生成差异 6.Viewing old file versions 查看旧的文件版本 7.Examples 实例 1.Counting the number of commits on a branch 统计一个分支中的交付数目 2.Check whether two branches point

5、at the same history 检查两分支是否在同一历史时期 3.Find first tagged version including a given fix 找到包含给定修正的第一个标签版本 4.Showing commits unique to a given branch 显示仅属于某个分支的交付 5.Creating a changelog and tarball for a software release 为软件的发行制作变更日志和压缩包 6.Finding commits referencing a file with given content 寻找一个指向包含给定内

6、容的文件的交 付 4.Chapter 3. Developing with git 第三章. 用 git 进行研发 1.Telling git your name 告诉 git 你的名字 2.Creating a new repository 创建新的版本库 3.How to make a commit 如何制作一个交付 4.Creating good commit messages 写好交付信息 5.Ignoring files 忽略文件 6.How to merge 如何合并 7.Resolving a merge 解决合并冲突 -_1.Getting conflict-resolutio

7、n help during a merge 在合并过程中取得冲突解决帮助 8.Undoing a merge 撤销合并 9.Fast-forward merges 快进合并 10. Fixing mistakes 修复失误 1.Fixing a mistake with a new commit 修复一个新的交付中的失误 11. Fixing a mistake by rewriting history 通过重写历史来修复失误 12. Checking out an old version of a file 提取一个文件的旧版本 13. Temporarily setting aside w

8、ork in progress 临时放下手头上的工作 14. Ensuring good performance 确保好的性能 15. Ensuring reliability 确保伸缩性 1.Checking the repository for corruption 检查版本的损坏 2.Recovering lost changes 恢复丢失的变更 5.Chapter 4. Sharing development with others 第四章. 与他人协同研发 1.Getting updates with git-pull 用 git-pull 取得更新 2.Submitting pat

9、ches to a project 向项目提交补丁 3.Importing patches to a project 给项目导入补丁 4.Public git repositories 发布 git 版本库 5.Setting up a public repository 建立一个公共版本库 6.Exporting a git repository via the git protocol 通过 git 协议公开版本库 7.Exporting a git repository via http 通过 http 协议公开版本库 8.Pushing changes to a public repo

10、sitory 将变更推入到公共版本库 9.What to do when a push fails 推入失败之后该怎么处理 10. Setting up a shared repository 建立共享版本库 11. Allowing web browsing of a repository 容许 Web 浏览版本库 12. Examples 例子 1.Maintaining topic branches for a Linux subsystem maintainer | Linux 子系统维护者如何维护主 题分支 6.Chapter 5. Rewriting history and mai

11、ntaining patch series 第五章. 改写历史与维护补丁串 1.Creating the perfect patch series 创建出色的补丁串 2.Keeping a patch series up to date using git-rebase 使用 git-rebase 保持补丁串的新颖 3.Rewriting a single commit 重写单个交付 4.Reordering or selecting from a patch series 在补丁串中选取与重新排序 5.Other tools 第三方工具 6.Problems with rewriting h

12、istory 重写历史带来的问题 7.Why bisecting merge commits can be harder than bisecting linear history 为何定位合并交付中的 问题要比在线性历史中困难 7.Chapter 6. Advanced branch management 第六章. 高级分支管理 1.Fetching individual branches 2.git fetch and fast-forwards 抓取与快进 3.Configuring remote branches 配置远程分支 8.Chapter 7. Git concepts 第七章

13、. Git 概念 1.The Object Database 对象数据库 1.Commit Object 交付对象 2.Tree Object 树对象 3.Blob Object 片对象 4.Trust 信赖 5.Tag Object 标签对象 6.How git stores objects efficiently: pack files | git 如何高效地储存对象: 打包文件 7.Dangling objects 悬空对象 8.Recovering from repository corruption 从损坏中恢复 2.The index 索引 9.Chapter 8. Submodu

14、les 子模块 -_1. 1.Pitfalls with submodules 子模块陷阱 10. Chapter 9. Low-level git operations 第九章. 底层 git 操作 1.Object access and manipulation 对象访问与操作 2.The Workflow 运作流程 1.working directory - index 工作树 - 索引 2.index - object database 索引 - 对象数据库 3.object database - index 对象数据库 - 索引 4.index - working directory

15、 索引 - 工作目录 5.Tying it all together 全盘了解 3.Examining the data 检验数据 4.Merging multiple trees 合并多个树 5.Merging multiple trees, continued 合并多个树,续完 11. Chapter 10. Hacking git 第十章. git 的开发 1.Object storage format 对象的存储格式 2.A birds-eye view of Gits source code 鸟瞰 git 源代码 12. Chapter 11. GIT Glossary 第十一章.

16、GIT 字典 13. Appendix A. Git Quick Reference 附录 A. Git 快速参考 1.Creating a new repository 创建一个新的版本库 2.Managing branches 管理分支 3.Exploring history 勘查历史 4.Making changes 制作变更 5.Merging 合并 6.Sharing your changes 共享你的变更 7.Repository maintenance 版本库的维护 8.Appendix B. Notes and todo list for this manual 附录 B. 备

17、忘与本手册的工作计划Preface 前言前言Git is a fast distributed revision control system. Git 是一个快速的分布式版本控制系统 This manual is designed to be readable by someone with basic UNIX command-line skills, but no previous knowledge of git. 这个手册是面向那些具有基本的 Unix 命令行使用技能,但是没有 Git 知识的人设 计的。 Chapter 1, Repositories and Branches an

18、d Chapter 2, Exploring git history explain how to fetch and study a project using gitread these chapters to learn how to build and test a particular version of a software project, search for regressions, and so on. 第一章 版本库与分支 和 第二章 考查 git 历史 将展示如何用 git 来获取和研究一个 项目,通过阅读这些章节,我们学习如何建立和测试一个具体的软件项目的版本, 学

19、习“撤退”等等。 -_People needing to do actual development will also want to read Chapter 3, Developing with git and Chapter 4, Sharing development with others. 人们是需要开展真正的研发工作的,那么就学习 第三章, 用 git 进行开发 和 第四 章,与他人共享研发成果。 Further chapters cover more specialized topics. 更多的一些章节会涉及到许多的专题话题。 Comprehensive reference

20、 documentation is available through the man pages, or git- help(1) command. For example, for the command “git clone “, you can either use: 参考文档可以通过系统的手册页命令,或者是 git-help(1) 命令来查看。譬如,你想 参考 “git clone “, 你可以用下面的两种方式: $ man git-cloneor: 或者: $ git help cloneWith the latter, you can use the manual viewer

21、of your choice; see git-help(1) for more information. 晚一点你就有机会用到这些手册查看器的;看 git-help(1) 会得到比较多的信息。 See also Appendix A, Git Quick Reference for a brief overview of git commands, without any explanation. 阅读 附录 A,那里是一个 git 命令的快速纵览,但是它不带任何的解说。 Finally, see Appendix B, Notes and todo list for this manual

22、 for ways that you can help make this manual more complete. 最后,看看 附录 B,这份手册的工作备忘和计划,通过它你可以帮助这份文档变 得更完善。 Chapter 1. Repositories and Branches 第第 一章一章. 版本库与分支版本库与分支-_How to get a git repository 如何获取一个版本库如何获取一个版本库It will be useful to have a git repository to experiment with as you read this manual. 有一个

23、实验性的 git 版本库对我们阅读这份手册将非常有用。 The best way to get one is by using the git-clone(1) command to download a copy of an existing repository. If you dont already have a project in mind, here are some interesting examples: 获取一个已经存在的版本库,最佳的方法是用 git-clone 命令,如果你还没有什么 心目中的项目的话,那么这里有些有趣的例子: # git itself (approx

24、. 10MB download): $ git clone git:/git.kernel.org/pub/scm/git/git.git# the Linux kernel (approx. 150MB download): $ git clone git:/git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.gitThe initial clone may be time-consuming for a large project, but you will only need to clone once. 对于一个大型项目

25、来说,初始性的克隆是挺费时的,不过克隆只需要做一次。 The clone command creates a new directory named after the project (“git“ or “linux-2.6“ in the examples above). After you cd into this directory, you will see that it contains a copy of the project files, called the working tree, together with a special top-level directory

26、 named “.git“, which contains all the information about the history of the project. 克隆命令会创建一个新的目录,并根据项目的名称来命名这个项目(譬如上说例子 中的 “git” 和 “linux-2.6”)。当你进入这个目录的时候,你可以看到它已经包含了 项目的所有文件,我们称之为工作树,在顶层目录中还连带了一个叫 “.git“ 的特殊 的目录,里面包含了项目的发展历史的所有信息。 How to check out a different version of a project 如何提如何提 取项目的不同版本取

27、项目的不同版本Git is best thought of as a tool for storing the history of a collection of files. It stores the history as a compressed collection of interrelated snapshots of the projects contents. In git each such version is called a commit. 最好将 git 当作是文件发展的历史纪录的收集工具,它压缩并保存了项目的发展的 关联性快照。在 git 中,每个这些变更称作交付

28、(commit)。 -_Those snapshots arent necessarily all arranged in a single line from oldest to newest; instead, work may simultaneously proceed along parallel lines of development, called branches, which may merge and diverge. 这些快照并不需要按从旧到新单线索地发展;它可以是同步并行地发展的,称之为 分支,它们是可以合并和分割的。 A single git repository

29、can track development on multiple branches. It does this by keeping a list of heads which reference the latest commit on each branch; the git-branch(1) command shows you the list of branch heads: 一个 git 版本库可以跟踪多个分支的发展,它通过保存一个分支头列表的方式来做 到这一点,每个分支头都是一个引用(reference),它指向该分支最后的一个交付 (commit); git-branch(1

30、) 命令可以向你展示每个分支头: $ git branch * masterA freshly cloned repository contains a single branch head, by default named “master“, with the working directory initialized to the state of the project referred to by that branch head. 一个刚刚克隆的版本库只包含一个分支头,默认叫 “master” (主分支),并且工 作目录已经被初始化为这个分支头所指向的项目状态。 Most proj

31、ects also use tags. Tags, like heads, are references into the projects history, and can be listed using the git-tag(1) command: 大部分的项目还用到标签(tags)。标签(Tags)就好像头(heads),它指向项目 的某个历史场面,它们可以通过 git-tag(1) 命令列举出来: $ git tag -l v2.6.11 v2.6.11-tree v2.6.12 v2.6.12-rc2 v2.6.12-rc3 v2.6.12-rc4 v2.6.12-rc5 v2.6

32、.12-rc6 v2.6.13 .Tags are expected to always point at the same version of a project, while heads are expected to advance as development progresses. -_Tags 被当做是项目统一的版本来对待,而 heads 则是项目前进的每一个步伐。 Create a new branch head pointing to one of these versions and check it out using git- checkout(1): 下面创建一个新的

33、分支头,使其指向其中的某个版本,同时将它提取出来,可以用 git-checkout(1) 命令: $ git checkout -b new v2.6.13The working directory then reflects the contents that the project had when it was tagged v2.6.13, and git-branch(1) shows two branches, with an asterisk marking the currently checked-out branch: 工作目录将被镜像为项目中标记为 v2.6.13 的版本

34、的内容,用 git-branch(1) 命令展 示这个两个分支,前面带星号(*)的就是当前抽取的分支。 $ git branchmaster * newIf you decide that youd rather see version 2.6.17, you can modify the current branch to point at v2.6.17 instead, with 如果你打算看看 2.6.17 的版本,你可以迁移你当前的分支,让它指向 2.6.17, 使用 一下命令: $ git reset -hard v2.6.17Note that if the current br

35、anch head was your only reference to a particular point in history, then resetting that branch may leave you with no way to find the history it used to point to; so use this command carefully. 注意,如果当前的分支头是你唯一的指向具体的历史场面的引用的话,那么复位 (resetting) 这个分支将令你无法找回这个分支以前的所有历史纪录,所以这个命令 要慎用。 Understanding History:

36、 Commits 理解历史:理解历史: 交付交付Every change in the history of a project is represented by a commit. The git-show(1) command shows the most recent commit on the current branch: -_项目的每一个历史变更体现为每一个交付 (commit)。git-show(1) 命令展示当前分支 的最新交付: $ git show commit 17cf781661e6d38f737f15f53ab552f1e95960d7 Author: Linus

37、Torvalds Date: Tue Apr 19 14:11:06 2005 -0700Remove duplicate getenv(DB_ENVIRONMENT) callNoted by Tony Luck.diff -git a/init-db.c b/init-db.c index 65898fa.b002dc6 100644 - a/init-db.c + b/init-db.c -7,7 +7,7 int main(int argc, char *argv) - char *sha1_dir = getenv(DB_ENVIRONMENT), *path; + char *sh

38、a1_dir, *path;int len, i;if (mkdir(“.git“, 0755) ocreate a new branch named , referencing the same point in history as the current branch o创建一个新的分支,并引用当前分支作为同一历史沿革 git branch ocreate a new branch named , referencing , which may be specified any way you like, including using a branch name or a tag na

39、me o创建一个名叫 的新分支,引用 ,它是 可以任意指定的,可以是现存的分支的名称或者是标签的名 称 git branch -d odelete the branch ; if the branch you are deleting points to a commit which is not reachable from the current branch, this command will fail with a warning. o删除一个叫 的分支;如果你要删除的这个分支所指 向的当前分支中一个不可及的交付的话,那么命令将返回失 败并作出提示 git branch -D oev

40、en if the branch points to a commit not reachable from the current branch, you may know that that commit is still reachable from some other branch or tag. In that case it is safe to use this command to force git to delete the branch. o尽管需要删除一个当前分支不可及的交付,但是你知道那个 交付仍然可有其他的分支或者是标签可及。在这种情况下, 用这个命令强制删除一个

41、分支是安全的。 git checkout omake the current branch , updating the working directory to reflect the version referenced by o提取分支,也即是引用 版本状态更新工作目录的内 容 git checkout -b ocreate a new branch referencing , and check it out. o引用 创建一个叫 的分支,并且将它提取 出来。 -_The special symbol “HEAD“ can always be used to refer to the

42、current branch. In fact, git uses a file named “HEAD“ in the .git directory to remember which branch is current: 特殊的标号 “HEAD“ 总是被用作引用,指向当前分支。事实上,git 是用 .git 目录 中的名叫 “HEAD“ 的文件来记住那个是当前分支。 $ cat .git/HEAD ref: refs/heads/masterExamining an old version without creating a new branch 不通过创建新分支来调查旧版本不通过创建新

43、分支来调查旧版本The git-checkout command normally expects a branch head, but will also accept an arbitrary commit; for example, you can check out the commit referenced by a tag: git-checkout 命令按常规是抽取分支头的,但是也可以接受任意的交付;例如,你 可以引用一个标签来进行提取。 $ git checkout v2.6.17 Note: moving to “v2.6.17“ which isnt a local bra

44、nch If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example:git checkout -b HEAD is now at 427abfa. Linux v2.6.17The HEAD then refers to the SHA1 of the commit instead of to a branch, and git branch shows that you are n

45、o longer on a branch: 此时,HEAD 将指向交付的 SHA1 来代替分支名称, git branch 命令表明你现在的 项目状态不从属于任何一个分支: $ cat .git/HEAD 427abfa28afedffadfca9dd8b067eb6d36bac53f $ git branch * (no branch)masterIn this case we say that the HEAD is “detached“. 这种情况,我们说 HEAD 是 “游离的”。 This is an easy way to check out a particular versio

46、n without having to make up a name for the new branch. You can still create a new branch (or tag) for this version later if you decide to. -_这是一个方便的途径,既可以提取某个版本,又避免了创建与命名一个新的分支。 如果你愿意,你当然还可以以这个版本为标本来创建一个新分支(或者是标签)。 Examining branches from a remote repository 调查远调查远 程版本库上的分支程版本库上的分支The “master“ branc

47、h that was created at the time you cloned is a copy of the HEAD in the repository that you cloned from. That repository may also have had other branches, though, and your local repository keeps branches which track each of those remote branches, which you can view using the “-r“ option to git-branch

48、(1): “master“ 分支是你克隆版本库的时候创建的,它是你的克隆的那个远程版本库上的 HEAD 的复件。那么远程版本库上可能还存在其他的分支,故而你的本地版本库 中也保留了那些远程分支的踪迹。你可以用 git branch(1) 命令加上 “-r“ 选项来查看。$ git branch -rorigin/HEADorigin/htmlorigin/maintorigin/manorigin/masterorigin/nextorigin/puorigin/todoYou cannot check out these remote-tracking branches, but you c

49、an examine them on a branch of your own, just as you would a tag: 你不可能将这些远程分支提取出来,但是你可以用一个你自己的分支来调查他们, 你当他们是一个标签好了。 $ git checkout -b my-todo-copy origin/todoNote that the name “origin“ is just the name that git uses by default to refer to the repository that you cloned from. 注意一下,“origin“ 是 git 用来指向你的版本库的克隆来源的默认名称。 Naming branches, tags, and other references 命名分支,命名分支,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com