You've just learned how to initialize your repository and
add commits to it using the staging area.
So far, each commit that you've made has built upon the previous commit,
creating a linear commit history.
Now let's take a look at some times when you might want to make a commit history
that branches out into multiple versions.
Making a straight line of changes makes a lot of
sense if you're just fixing bugs, adding new features or updating documentation.
But what if you wanted to try out a new experimental feature that
you're still not sure will work, but you still want to have a working demo to
show your friends when they ask what you're working on?
Or maybe you're learning Italian and want to make a version of your project for
Italian-speaking people while leaving the native language version intact.
In this case, you'll probably want to eventually create a setting for
switching between the two languages.
But maybe as a first step, you just try changing the text and
seeing if you need to rework your layout a little.
Of course, you could just make your changes and
record the IDs for all the commits.
And then use git checkout to jump back to the real official version when you
need to show it to somebody.
And then back to your other version afterward.
But what if you find a bug in your real official version and
you need to make a fix there?
You need to update your records and use this new commit as your real version.
This would be a lot of overhead.
To make this kind of situation easier, Git allows you to create labels for
your commits.
These labels are called branches.
In this case, we would have three different branches.
First, we would have master.
Master is the name given to main branch in most Git repositories and
every time you create a repository, Git creates a master branch for you.
This branch we would probably call something like italian and
this one we might call experimental or maybe just exp for short.
Remember how in last lesson when you checked out some old commits,
you'd get the detached head message?
Basically at that point, Git was warning you that you were looking at
a commit that was not labeled with a branch name.
So far, you've always been in a detached head state or on the master branch,
which Git creates for you.
It's possible to check out a branch in the same way you checked out commits in
the past, except with the hopefully human-readable branch name rather than
an unpronounceable series of characters.
If you check out a branch and
then make a commit, the branch label automatically updates to the new commit.
That branch also stays checked out, so you don't have to check it out again.
This is how you've managed to stay on the master branch without knowing anything
about branches up til this point.
As a matter of terminology, we sometimes refer to the current last commit on
a branch as being the tip of that branch.
It is possible to have multiple branch labels attached to a single commit, but
making a new commit will only update the branch that you have checked out and
leave any others alone.
At this point,
it's natural to wonder if there's any way to combine two branches,
say if your experimental feature has finally worked out, but
your main branch has grown since the two diverged.
The process of combining two commits is known as merging and
we'll get to that later on in the lesson.
But first, we want you to get comfortable creating, checking out and
committing to branches.
Caroline will help you get started with this.
لقد تعلمتم كيفية تهيئة المستودع الخاص بكم
.وإضافة تثبيتات إليه باستخدام منطقة الإعداد
وحتى الآن، كل تثبيت قمتم به مبني على التثبيت السابق؛
.مما يؤدي إلى إنشاء سجل تثبيت خطي
والآن لنلق نظرة على المرات التي قد تريدون فيها إنشاء سجل تثبيت
.يشمل إصدارات متعددة
قد يكون إجراء تغييرات مباشرة مناسبًا
.إذا كنتم تقومون بإصلاح مشكلات أو إضافة ميزات جديدة أو تحديث وثائق
ولكن إذا كنتم ترغبون في تجربة ميزة تجريبية جديدة
وأنتم غير متأكدين مما إذا كانت ستعمل أم لا ولكنكم تريدون إصدارًا تجريبيًا عاملاً
لتعرضوه على أصدقائكم عندما يسألونكم عما أنجزتموه؟
أو ربما تتعلمون اللغة الإيطالية وترغبون في إنشاء إصدار من مشروعكم
.للمتحدثين بالإيطالية مع الاحتفاظ بإصدار اللغة الأصلية بحالة جيدة
في هذه الحالة، تحتاجون إلى إنشاء إعداد
.للتبديل بين اللغتين
ولكن كخطوة أولى قوموا بتغيير النص ومراقبة
.ما إذا كان يحتاج إلى تعديل التخطيط قليلاً
يمكنكم بالطبع إجراء التغييرات
.وتسجيل المعرفات لكل التثبيتات فحسب
وبعد ذلك استخدموا git checkout للرجوع إلى الإصدار الرسمي الحقيقي
.عند الحاجة إلى عرضه على أحدهم
.ثم ارجعوا إلى الإصدار الآخر بعد ذلك
ولكن ماذا لو وجدتم خطأً في الإصدار الرسمي الحقيقي
وتريدون إصلاحه؟
.تحتاجون إلى تحديث سجلاتكم واستخدام هذا التثبيت الجديد بصفته إصداركم الحقيقي
.قد يبدو ذلك عملاً زائدًا شاقًا
ولجعل هذا الأمر أكثر سهولة، يسمح لكم Git بإنشاء تسميات
.للتثبيتات الخاصة بكم
.يطلق على هذه التسميات فروع
.وفي هذه الحالة، سيكون لديكم ثلاثة أفرع مختلفة
.أولاً، يكون لديكم master
وهو الاسم الذي يُطلق على الفرع الرئيسي في أغلب مستودعات Git
.وفي كل مرة تقومون فيها بإنشاء مستودع، يقوم Git بإنشاء فرع رئيسي لكم
،يمكن أن نسمي هذا الفرع italian
.وربما نسمي هذا experimental أو exp فقط للإيجاز
تذكروا كيف حصلتم على "رسالة رأس" منفصلة عندما قمنا في الدرس السابق
بالتحقق من بعض التثبيتات القديمة؟
يقوم Git في الأساس بتحذيركم في هذا الموقف حيث إنكم تنظرون إلى
.تثبيت غير مسمى باسم فرع
وحتى الآن، تكونوا دائمًا في حالة الرأس المنفصل أو الفرع الرئيسي
.الذي قام Git بإنشائه لكم
من الممكن أن تقوموا بسحب فرع بنفس الطريقة التي قمتم بسحب التثبيتات بها
من قبل، باستثناء أننا نأمل في اسم فرع يمكن قراءته بدلاً من
.سلسلة الحروف التي لا يمكن نطقها
إذا قمتم بسحب فرع
.وقمتم بتثبيت ما، يتم تحديث تسمية الفرع بالتثبيت الجديد تلقائيًا
.يظل هذا الفرع مسحوبًا، وبذلك لا يجب عليكم سحبه مرة أخرى
وهكذا تمكنتم من البقاء في الفرع الرئيسي بدون معرفة أي شيء
.عن الفروع حتى هذه النقطة
وفيما يتعلق بالمصطلحات، نشير أحيانًا إلى آخر تثبيت جارٍ
.في الفرع كرأس هذا الفرع
من الممكن أن يكون لديكم تسميات فروع متعددة مرتبطة بتثبيت واحد ولكن
القيام بتثبيت جديد سيؤدي فقط إلى تحديث الفرع الذي قمت بسحبه
.ويترك الأخرى
وحتى الآن
،من الطبيعي أن تتساءلوا عما إذا كانت هناك طريقة لجمع فرعين
لنقل في حالة نجاح ميزتكم التجريبية أخيرًا، ولكن
.فرعكم الرئيسي قد نما بينما الفرعان اختلفا وتشعبا
تعرف عملية جمع تثبيتين بالدمج
.وسنتطرق لذلك فيما بعد في هذا الدرس
ولكن نريدكم أن تتمكنوا بسهولة من إنشاء وسحب
.وتثبيت هذه الفروع
.ستساعدكم كارولين على البدء في ذلك
저장소를 시작하는 방법과
스테이지 영역에서
커밋하는 방법을 배웠습니다
지금까지 했던 커밋은
이 전의 커밋에 추가하는
직선적인 기록이었습니다
이번에는 브랜치를 이용해서
여러 버전의 기록을
커밋하는 방법을
살펴보겠습니다
직선적으로 변경하는 것은
버그를 수정이나
새로운 기능 추가
문서 업데이트에서는 당연합니다
작동에 확신이 없는
실험적인 기능이지만
시험작을 만들어서
주위 사람들에게
보여주려고 할 때는 어떨까요?
아니면 이탈리아 말을 배워서
현재 모국어인 프로젝트의
이탈리아 버전을 만들려고
시도할 때는 어떨까요?
이 경우, 두 언어간의
전환을 위한
설정을 만들고 싶지 않을까요?
하지만 첫 단계에서는
텍스트를 변경하고
레이아웃을 살짝 바꾸는
정도만 가능할지도 모릅니다
물론, 변경을 한 다음
커밋의 ID 를
기록하는 방법도 있습니다
그리고 누군가에게
보여주고 싶을때는
커밋 ID를 이용해
체크아웃을 하는 거죠
그런 다음 다시
현재 버전으로 돌아오면 됩니다
하지만 현재 공식 버전에서
버그를 발견하고
수정을 해야한다면
어떨까요?
기록했던 커밋과 현재 버전
모두를 수정해야 합니다
너무 큰 오버헤드입니다
이런 상황을 위해서
Git 은 분기를
가질 수 있도록 지원합니다
이 분기를
브랜치 라고 부르죠
이 경우에
세 가지 브랜치를 갖습니다
하나는 마스터입니다
마스터는 대부분의 Git 저장소에서
메인 브랜치의 이름입니다
저장소를 생성하면
Git 은 마스터 브랜치를 제공합니다
이탈리안 이라고 부를 수 있는
브랜치와
실험 이라고 부를 수 있는
브랜치도 있습니다
예전 버전의 커밋으로 체크아웃하면
나오는 분리된 머리 메시지를
기억 하나요?
사실 그 시점에서
Git 은 분류되지 않은
커밋을 보고 있다고
경고했습니다
지금까지는 항상
분리된 머리 상태이거나
Git 이 제공한
마스터 브랜치였습니다
이 전에 체크아웃 했던 방식으로
브랜치에 체크아웃 할 수 있는데
읽을 수 없는 문자의 나열이 아닌
사람이 읽을 수 있는
브랜치 이름으로
접근할 수 있습니다
어떤 브랜치에 체크아웃 하고
커밋을 하면
새로운 커밋에
자동으로 브랜치 이름이 붙고
브랜치는 체크아웃
상태가 유지됩니다
그렇기 때문에 지금까지
브랜치에 대해 전혀 모르고도
마스터 브랜치를 관리할 수
있었던 것입니다
용어적인 문제로
브랜치의 현재 최근 커밋을
그 브랜치의 끝이라고 합니다
한 커밋에서 여러 브랜치를
만드는 것도 가능하지만
커밋은 체크아웃한
브랜치에만 적용되고
나머지는 적용되지 않습니다
이 시점에서
두 브랜치를 합치는 방법이
궁금해질 것입니다
만약 실험적인
기능이 완성되었고
메인 브랜치도 갈라져서
발전해 온 경우에 말이죠
두 커밋을 합치는 작업을
머지라고 하고
다음에 다룰 것입니다
하지만 우선은
브랜치의 생성과
체크아웃과 커밋에
익숙해져야 합니다
캐롤라인이 도와줄 것입니다
Você aprendeu como inicializar seu repositório e
adicionar commits a ele usando a área de preparação.
Até agora, cada commit que você criou se baseou no commit anterior,
formando um histórico linear de commits.
Agora vamos ver situações em que pode ser bom criar um histórico de commits
que se ramifica em várias versões.
Gerar uma linha reta de alterações faz muito
sentido se você está só corrigindo bugs, adicionando novos recursos ou atualizando a documentação.
Mas, e se você quiser tentar um novo recurso experimental que
ainda não sabe se vai funcionar e quiser ter uma demonstração operacional
para mostrar aos seus amigos quando eles perguntarem em que você está trabalhando?
Ou talvez você esteja aprendendo italiano e queira fazer uma versão do seu projeto
para falantes de italiano, deixando intacta a versão do seu idioma nativo.
Nesse caso, é provável que você depois queira criar uma configuração para
alternar entre os dois idiomas.
Mas, como primeiro passo, apenas tente alterar o texto e
ver se é preciso reelaborar o layout.
Claro que você pode só fazer as alterações e
registrar as IDs de todos os commits.
E depois usar git checkout para voltar para a versão oficial real quando
precisar mostrá-lo a alguém.
E depois voltar para a outra versão.
Mas, e se você encontrar um bug na versão oficial real e
precisar fazer uma correção lá?
Você precisaria atualizar seus registros e usar esse novo commit como a versão real.
Isso daria um bocado de trabalho extra.
Para facilitar essas situações, o Git permite a criação de rótulos para
os commits.
Esses rótulos são chamados de branches.
Neste caso, teríamos três branches diferentes.
Primeiro, teríamos o master.
Master é o nome dado ao branch principal na maioria dos repositórios Git.
Cada vez que você cria um repositório, o Git cria um branch master.
Este branch provavelmente teria um nome como italian e
este aqui poderíamos chamar de experimental, ou exp para abreviar.
Lembra-se, na última lição, de quando você fez o check-out de commits antigos
e recebeu a mensagem de HEAD desanexado?
Basicamente, naquele ponto, o Git estava avisando que aquele era
um commit que não estava rotulado com um nome de branch.
Até agora, você sempre esteve em um estado de HEAD desanexado ou no branch master,
que o Git cria para você.
É possível fazer o check-out de um branch do mesmo modo que você fez o check-out de
commits antes, só que com um nome de branch que um humano possa ler em vez de
uma série impronunciável de caracteres.
Se você fizer o check-out de um branch e
depois criar um commit, o rótulo do branch será atualizado automaticamente para o novo commit.
Esse branch também continua em check-out, então não é preciso fazer o check-out de novo.
Foi assim que você conseguiu se manter no branch master sem saber nada
sobre branches até agora.
A título de terminologia, às vezes nos referimos ao último commit atual de
um branch como a ponta desse branch.
É possível ter vários rótulos de branches anexados a um único commit, mas
a criação de um novo commit só atualizará o branch que está em check-out e
deixará os outros quietos.
Neste ponto,
é natural imaginar se há uma forma de combinar dois branches;
por exemplo, caso o recurso experimental tenha ficado pronto, mas
o branch principal tenha crescido depois que os dois divergiram.
O processo de combinar dois commits é conhecido como fusão, e
vamos falar dele mais tarde na lição.
Primeiro, familiarize-se com as tarefas de criar branches, fazer check-out e criar
commits em branches.
Caroline vai ajudá-lo a começar.
你刚刚学习了如何初始化版本库
并使用暂存区向其中添加 commit
到目前为止 每个 commit 都是基于之前的 commit
形成了一个线性 commit 历史记录
现在我们来看看 有时候你可能想要对 commit 历史记录进行分支
产生多个版本
如果你只是修复下 bug 添加新的更改或更新文档
则形成直线更改比较合理
如果你想要尝试一种新的实验性功能
并且不确定该功能是否可行 但是依然想要一个可行的演示
当好友问你的工作情况时 你可以向他们展示
或者你正在学习意大利语 并且想要制作一个面向意大利语用户的项目版本
同时不影响母语版本
在这种情况下 你需要最终创建一个设置
用于在这两种语言之间切换
或许第一步只是想要更改文本
看看是否需要更改下布局
当然 你可以进行更改
并记住所有 commit 的 ID
当你需要向他人展示实际的正式版时
使用 git checkout 返回到该版本
然后再返回到其他版本
如果你在实际的正式版中发现一个 bug
需要修复该 bug 该怎么办?
你需要更新你的记录 使用这个新的 commit 作为你的实际版本
这样会比较复杂
为了轻松地处理这种情形 Git 使你能够
标记你的 commit
这些标记叫做分支
在这种情况下 我们有三个不同的分支
首先是 master 分支
master 分支是指大多数 Git 版本库中主要分支的名称
每次创建版本库时 Git 都会为你创建一个 master 分支
这个分支可以叫做意大利语
这个可以叫做实验性 或者简称 exp
还记得在上节课中 当你检出一些旧的 commit
会收到 detached head 消息吗?
在这种情况下 Git 是在警告你 你所研究的这个 commit
没有用分支名称进行标记
到目前为止 你一直处于游离状态或位于 master 分支上
master 分支是 Git 为你创建的
我们可以按照之前检出 commit 的方式检出分支
只是使用的是人类能看懂的分支名称
而不是读都读不通的一串字符
如果你检出一个分支
然后进行 commit 分支标记会自动更新到新的 commit 上
该分支也会保持检出状态 所以你不用再次检出
这也是你为何到目前为止一直待在 master 分支上
不知道任何分支情况
说到术语 有时候我们将分支中的当前最后一个 commit
称为该分支的顶点
单个 commit 上可能会出现多个分支标记
但是进行新的 commit 只会更新你检出的分支
其他分支不受影响
此时
你可能会好奇是否能够合并两个分支
例如你的实验性功能终于可行了
但是在这个分支从 master 分支上分叉后 master 分支已经延长了
合并两个 commit 的流程称为合并
我们将在课程的后续部分介绍到
首先希望你能熟练地创建 检出和向分支中
commit 更改
Caroline 将帮助你熟练地掌握这些操作