首页 iOS.& Swift Books Git学徒

8
合并 由Chris Belanger撰写& Sam Davies

分支存储库只是支持并行和并发开发的前半部分;最终,您必须将所有这些分支位重新放在一起。并且,是的,该操作可以像你认为的那样复杂!

合并 git结合你所做的是什么,他人的工作是机制。由于GIT支持数百人的工作流程,如果不是数千个,贡献者都分开工作,Git就可以了尽可能多的繁重升降。偶尔,你必须介入并帮助放大一点,口袋,大部分,合并可以,应该是一个相当无痛的手术。

要开始本章,导航到 思想 您通过这本书使用的目录。

看看你的分支机构

To start, switch to the clickbait branch of this repository with the following command:

git checkout clickbait

如果你要想象你当前的分支历史 思想 repository, with you sitting on the clickbait branch, it would look something like this :

在上面的图像中,您可以看到以下内容:

  1. This is your local master branch. The bottom of the graph represents the start of time as far as the repository is concerned, and the most recent commit is at the top of the graph.
  2. This is the master branch on origin — that is, the remote repository. You can see the point where you cloned the repository, and that you’ve made some local commits since that point.
  3. This is the clickbait branch, and since this is the branch you just switched to, you can see the HEAD label attached to the tip of the clickbait branch. You can see that this branch was created off of master some time before you cloned the repository.
  4. This is an old branch that was created off of master at some time in the past, and was merged back to master a few commits later. This branch has since been deleted, since it had served its purpose and was no longer needed.

This is a fairly common development workflow; in a small team, master can effectively serve as the main development line, and developers make branches off of master to work on features or bug fixes, without messing with what’s in the main development line. Many teams consider master to represent “what is deployed to production”, since they see master as “the source of truth” in their development environment.

在你进入合并,你应该花点时间变得有点“占有欲”术语的直线。

When Git is ready to merge two files together, it needs to get a bit of perspective first as to which branch is which. Again, there’s nothing special about master, so you can’t always assume you’re merging your branch back that way. In practice, you’ll find that you often merge between branches that 不是 master.

因此,Git在方面思考分支 我们他们的。 “我们的”是指你融为一谈的分支,“他们的”是指你想要进入“我们的”的分支。

Let’s say you want to merge the clickbait branch back into master. In this case, as shown in the diagram below, master is 我们 和 the clickbait branch would be 他们的。保持这种区别直将帮助您不可估量在你的职业生涯的合并。

三路合并

您可能会认为合并真的只是在每个分支上进行两个修订,一个在每个分支中,并以逻辑的方式将它们捣碎。这将是一个 双向 合并,这是我们大多数人思考世界的方式:由两个现有元素组成的一个新元素只是每个元素的唯一和常见部分的联盟。然而,Git实际使用的合并 修改以表现所谓的东西 三路合并.

原始文件。
LTE AWEKOQUJ JAPA。

克里斯'左边的变化;萨姆的右边的变化。
NMNOH'VDUDDIF AG JSA YICW; tol'd htikbiq aj zba zuqyf。

没有出发点的背景,负责合并的人员试图保留尽可能多的线,这两个文件都是共同的。
Cehc tu zawhrxuabv az mgex cji lmacpaxm ruusk mid,gmu memjow putwetyunya fu yette mqauz xu qpoyiptum pacl cilow il tascenwe ak bimjex su xakf nidaq。

知道每组更改的原点允许您检测到克里斯删除第1行,并由SAM添加第4行。
SXOLIZM NHO EHOKOY OG UELM MAM OP ZMUZKIM LOI SIBIWD QLUD JIQA 3 SUG HITACEB TYZHEN,UHR PIGU 4 DUJ IHHAK WZ ZIB。

结果是你们两个意图。
jhi mikubj ep jqiy weu buhk oszabcin。

合并分支

In this scenario, you’re going to look at the work that someone else has made in the clickbait branch of the 思想 repository, and merge those changes back into master.

git checkout clickbait
git log clickbait --not master
commit e69a76a6febf996a44a5de4dda6bde8569ef02bc (HEAD -> clickbait, origin/clickbait)
Author: Chris Belanger <[email protected]>
Date:   Thu Jan 10 10:28:14 2019 -0400

    Adding suggestions from Mic

commit 5096c545075411b09a6861a4c447f1af453933c3
Author: Chris Belanger <[email protected]>
Date:   Thu Jan 10 10:27:10 2019 -0400

    Adding first batch of clickbait ideas
cat articles/clickbait_ideas.md
git checkout master
cat articles/clickbait_ideas.md
git merge clickbait
*   55fb2dc (HEAD -> master) Merge branch 'clickbait' into master
|\
| * e69a76a (origin/clickbait, clickbait) Adding suggestions from Mic
| * 5096c54 Adding first batch of clickbait ideas
* | 477e542 Adding .gitignore files and HTML
* | ffcedc2 Adds all the good ideas about management
* | 8409427 Removes terrible live streaming ideas
* | 67fd0aa Moves platform ideas to website directory
* | 0ddfac2 Updates book ideas for Symbian and MOS 6510
* | 6c88142 Adding some tutorial ideas
* | ce6971f Adding empty tutorials directory
* | 57f31b3 Added new book entry and marked Git book complete
* | c470849 (origin/master, origin/HEAD) Going to try this livestreaming thing
* | 629cc4d Some scratch ideas for the iOS team
|/
* fbc46d3 Adding files for article ideas
*   5fcdc0e Merge branch 'video_team'
|\
| * cfbbca3 Removing brain download as per ethics committee
| * c596774 Adding some video platform ideas
| * 06f468e Adding content ideas for videos
* | 39c26dd I should write a book on git someday
* | 43b4998 Adding book ideas file
|/
* becd762 Creating the directory structure
* 7393822 Initial commit
cat articles/clickbait_ideas.md

前进合并

有合并的另一种类型是发生在Git的,被称为 快进 合并。为了说明这一点,请思考上面的示例,您和您的朋友正在申请文件。你的朋友已经离开了(可能被谷歌或苹果,幸运SOD)雇用,你现在自己在这个文件上工作。

如果有其他的修改文件合并,简单的Git提交您的文件通过原有的顶部。
六EM hgugi AJI onzem xlacnof双DXA mevi hopko,JEH gorzpf vovqamc满足vawo obun ZEF版HGE avulipuh。

git checkout master
git checkout -b readme-updates
This repository is a collection of ideas for articles, content and features at raywenderlich.com.

Feel free to add ideas and mark taken ideas as "done".
git add README.md
git commit -m "Adding more detail to the README file"
git checkout master
git log --oneline --graph --all
* 78eefc6 (readme-updates) Adding more detail to the README file
*   55fb2dc (HEAD -> master) Merge branch 'clickbait' into master
git merge readme-updates
~/GitApprentice/ideas $ git merge readme-updates
Updating 55fb2dc..78eefc6
Fast-forward
 README.md | 4 ++++
 1 file changed, 4 insertions(+)
git log --oneline --graph --all
* 78eefc6 (HEAD -> master, readme-updates) Adding more detail to the README file
*   55fb2dc Merge branch 'clickbait' into master

迫使合并提交

You can force Git to not treat this as a fast-forward merge, if you don’t want it to behave that way. For instance, you may be following a particular workflow in which you check that certain branches have been merged back to master before you build.

挑战:创建非快速转发合并

For this challenge, you’ll create a new branch, make a modification to the README.md file again, commit that to your branch, and merge that branch back to master as a non-fast-forward merge.

关键点

  • 合并 联合收割机上工作与另一个分支所做的工作一个分支完成。
  • git表演 三路合并 to combine content.
  • 我们 指的是要拉变为分支; 他们的 是指具有要拉成的变化分支 我们.
  • git log <theirs> --not <ours> 你说明了什么提交上要合并的分支,是不是在你的分支了。
  • git merge <theirs> 合并的“他们”分支提交到“我们”的分支。
  • Git的自动创建一个合并提交信息给你,并让你与合并,然后再继续编辑。
  • A 快进 由于您分支出“他们的”,因此没有改变“我们的”,并且没有合并提交,因此不会发生“我们的”。
  • To prevent a fast-forward merge and create a merge commit instead, use the --no-ff option with git merge.

然后去哪儿?

如果分支是 Git,然后将分支机构合并回来将是 。虽然这个概念很简单 - 与他们的变化结合在实践中,人们在Git中很容易绊倒,因为合并并不总是像你假设一样工作。

有一个技术问题?想报告一个错误吗? 你可以问的问题和bug报告本书的作者在我们的官书论坛 这里.

有反馈分享在线阅读体验吗? 如果您有关于UI,UX,突出显示或我们在线阅读器的其他功能的反馈,您可以将其发送到设计团队,其中表格如下所示:

© 2021 Razeware LLC

您正在阅读的自由,以显示为本章的部分 混淆了 文本。解锁这本书,以及我们整个书籍和视频目录,带有Raywenderlich.com的专业订阅。

现在解锁

为了突出或做笔记,你需要通过自己拥有这本书的订阅或能力。