Version control and teamwork
Diperkenalkan
6:03
Rekayasa Perangkat Lunak
Software engineering is how systems outlive their authors. The first three units shape the product: requirements, architecture and interface design. The next…
Narasi bahasa Inggris · takarir bahasa Inggris dan 中文 yang dapat dipilih
Dalam pelajaran ini
| English | Makna |
|---|---|
| branching model/ˈbræntʃɪŋ ˈmɒdl/ | model percabangan |
| pull request/pʊl rɪˈkwest/ | a request to merge one branch's changes into another, usually with review |
| merge conflict/mɜːdʒ ˈkɒnflɪkt/ | The tool telling you that two decisions collided. |
| Merge/mɜːdʒ/ | combining the histories of two branches |
| commit/kəˈmɪt/ | a saved snapshot of changes in version control |
| code review/kəʊd rɪˈvjuː/ | another developer reading changes before they are merged |
| Rebase/rɪˈbeɪs/ | moving a branch's commits so they start from a newer base commit |
| Semantic versioning/səˈmæntɪk ˈvɜːʃənɪŋ/ | MAJOR.MINOR.PATCH version numbers that signal breaking changes, new features and fixes |
| base/beɪs/ | the commit that a branch starts from |
Main stays releasable
- The course repository's branching model 分支模型:
maincan always be released, feature branches live only a short time, and every change goes through a pull request 拉取请求 with review. - A merge conflict 合并冲突 is the tool telling you that two decisions collided.

In the course model, main is —
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Short-lived branches merge back through reviewed pull requests.
The everyday commands
- One feature, from a new branch to a pull request 拉取请求:
# new branch from main
git switch -c loan-limit
# ...edit and test, then:
git add src/loans.py
git add tests/test_loans.py
git commit -m "Loan limit 6 (REQ-12)"
# send it, then open a PR
git push -u origin loan-limit
- After the pull request is reviewed and merged,
git switch mainandgit pullbring your copy up to date, and the short-lived branch is deleted.git statusandgit log --onelineshow where you are at any point.
You have edited two files and want to record them as one commit on your feature branch. Which pair of commands does that?
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
git add stages the changed files; git commit records the staged changes as one commit with its message. Push only sends commits that already exist.
The size of a commit
- One commit 提交 is one change you can defend, linked to its requirement, with the tests green at every commit. Bisect depends on this: a history that runs at every commit narrows a regression to one change in $\log_2 n$ checkouts, so 12 commits need at most 4.
- Huge commits ("a week of work") make bisect useless, and a merge commit with no message loses the decision.
Bisect over 12 runnable commits needs at most —
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
log2(12) rounded up: 4 checkouts narrows the regression.
The conflict and the review
- Two branches edit
LOAN_LIMIT: one raises it to 6, the other moves it to a config file. The resolution is a decision, and it belongs in the merge commit's message. A conflict resolved silently is a lost decision. - The code review 代码审查 contract: the diff, the tests and a link to the requirement, under about 200 changed lines. Review against the acceptance test, not against personal taste.
A conflict resolution belongs —
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
The resolution is a decision: record it where the code lives.
Merge, rebase and bisect
- Merge 合并 joins two histories and keeps both as they happened. Rebase 变基 replays your commits on top of
mainto give a straight line, but it rewrites them, so never rebase a branch that others have already pulled. git bisecthalves the range of suspects with each test: $100$ commits need at most $\lceil \log_2 100 \rceil = 7$ checkouts. Each tested commit must be usable with a test that distinguishes good from bad revisions.
A regression hides somewhere in 1000 commits. At most how many bisect checkouts find it?
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
2^10 = 1024 is at least 1000, so 10 halvings suffice.
Rebasing a branch that teammates have already pulled is safe.
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Rebase rewrites the commits, so their copies no longer match and must be repaired by hand.
Version numbers that mean something
- Semantic versioning 语义化版本 writes MAJOR.MINOR.PATCH. From 2.3.1, a bug fix gives 2.3.2, a new feature that keeps old code working gives 2.4.0, and a breaking change gives 3.0.0.
- The number is a promise: a library user can take any 2.x update safely, but must read the notes before moving to 3.0.
Version 2.3.1 gains a new, backward-compatible API call. The next version is:
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
A compatible feature bumps MINOR and resets PATCH.
Worked example: the three-way merge
- Git compares both branches with their common base 基础版本. The base has
LOAN_LIMIT = 5; your branch makes it 6; their branch leaves that line alone and edits another file. Only one side changed the line, so git takes 6, with no conflict. - If their branch had changed it to 4, both sides would have changed the same line in different ways: a conflict. Git stops and marks the file:
<<<<<<< HEAD
LOAN_LIMIT = 6
=======
LOAN_LIMIT = 4
>>>>>>> their-branch
- A person decides: edit the file to the value you agree on, delete the three marker lines, then
git addand commit, saying why in the message. Most of what looks like "merge magic" is this one rule.
In a three-way merge, a line changed on only one branch causes a conflict.
Kesulitan 1/5 · 100 koin + bonus kecil pada penyelesaian pertama hari ini
Git takes the changed side; a conflict needs both sides to change it differently.
Most checkouts git bisect needs to find the bad commit among 1000?
Kesulitan 2/5 · 140 koin + bonus kecil pada penyelesaian pertama hari ini
$\lceil\log_2 1000\rceil = 10$.
Marks that slip away
- Rebasing a shared branch. It rewrites commits 提交 that others have already pulled.
- Huge commits. A week of work in one commit leaves bisect nothing to narrow.
- Resolving a conflict silently. The resolution is a decision; record it in the merge message.
Recap
mainstays releasable; feature branches are short-lived; pull requests get reviewed.- One commit is one change you can defend, linked to its requirement.
- A conflict resolution is a decision: record it in the merge message.
- Semantic versioning 语义化版本, starting from 2.3.1:
| Change | New version |
|---|---|
| Bug fix | 2.3.2 |
| New feature, old code still works | 2.4.0 |
| Breaking change | 3.0.0 |
Apa yang salah? Hanya tim situs yang dapat melihatnya.