Skip to content

Commit 360d4a5

Browse files
committedSep 24, 2020
Edit using git page for brevity and clarity.
The previous iteration of the page was often wordy and occasionally unclear. This has been cleaned up in places. Additionally, the TODO in the no-merge policy section has been removed and addressed.
1 parent 7885733 commit 360d4a5

File tree

2 files changed

+36
-52
lines changed

2 files changed

+36
-52
lines changed
 

‎src/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
- [Introduction](./contributing.md)
3333
- [About the compiler team](./compiler-team.md)
34+
- [Using git](./git.md)
3435
- [Mastering @rustbot](./rustbot.md)
3536
- [Walkthrough: a typical contribution](./walkthrough.md)
36-
- [Using git](./git.md)
3737
- [Bug Fix Procedure](./bug-fix-procedure.md)
3838
- [Implementing new features](./implementing_new_features.md)
3939
- [Stability attributes](./stability.md)

‎src/git.md

+35-51
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,21 @@ can be incorporated into the compiler.
88

99
The goal of this page is to cover some of the more common questions and
1010
problems new contributors face. Although some git basics will be covered here,
11-
if you have never used git or GitHub before you may find that this is still a
12-
little too fast for you. In that case, it would make sense to first read some
13-
introductions to git, such as the Beginner and Getting started sections of
14-
[this tutorial from Atlassian][atlassian-git]. GitHub also provides
15-
[documentation] and [guides] for beginners.
11+
if you find that this is still a little too fast for you, it might make sense
12+
to first read some introductions to git, such as the Beginner and Getting
13+
started sections of [this tutorial from Atlassian][atlassian-git]. GitHub also
14+
provides [documentation] and [guides] for beginners, or you can consult the
15+
more in depth [book from git].
1616

17+
[book from git]: https://git-scm.com/book/en/v2/
1718
[atlassian-git]: https://www.atlassian.com/git/tutorials/what-is-version-control
1819
[documentation]: https://docs.github.com/en/github/getting-started-with-github/set-up-git
1920
[guides]: https://guides.github.com/introduction/git-handbook/
2021

21-
Although this page should get you to a point where you can start contributing,
22-
learning more git is almost certainly a good use of your time if you want to
23-
keep contributing. There are many tutorials online for those folks that are
24-
newer which combine excellently with man pages and official documentation.
25-
2622
## Prequisites
2723

2824
We'll assume that you've installed git, forked [rust-lang/rust], and cloned the
29-
forked repo to your PC. We'll also use the command line interface to interact
25+
forked repo to your PC. We'll use the command line interface to interact
3026
with git; there are also a number of GUIs and IDE integrations that can
3127
generally do the same things.
3228

@@ -80,34 +76,27 @@ the same, with some steps skipped:
8076
## Conflicts
8177

8278
When you edit your code locally, you are making changes to the version of
83-
rust-lang/rust that existed the last time you ran `git pull rust master` on
84-
your master branch. As such, when you submit your PR it is possible that some
85-
of the changes that have been made to rust-lang/rust since then are in conflict
86-
with the changes you've made; maybe someone else changed the same lines of
87-
code, or git cannot figure out how to merge your changes with the others for
88-
another reason.
79+
rust-lang/rust that existed when you created your feature branch. As such, when
80+
you submit your PR it is possible that some of the changes that have been made
81+
to rust-lang/rust since then are in conflict with the changes you've made.
8982

9083
When this happens, you need to resolve the conflicts before your changes can be
91-
merged. First, get a local copy of the conflicting changes. Checkout your local
92-
master branch with `git checkout master`. Then, `git pull rust master` to
84+
merged. First, get a local copy of the conflicting changes: Checkout your local
85+
master branch with `git checkout master`, then `git pull rust master` to
9386
update it with the most recent changes.
9487

9588
### Rebasing
9689

9790
You're now ready to start the rebasing process. Check out the branch with your
98-
changes, and then execute `git rebase master`.
99-
100-
First, a little background: In git, commits are stored as "diffs" which are a
101-
record of all the changes that a commit made to its parent. When you rebase a
102-
branch, all the changes in the commits on that branch are reapplied on the
103-
branch you are rebasing on top of (in this case master). In other words, git
104-
tries to pretend that the changes you made to the old version of master were
105-
instead made to the new version of master.
106-
107-
During rebasing, you should expect to encounter at least one "rebase conflict."
108-
This happens when git's attempt to reapply the changes onto the more recent
109-
version of master fails because your changes conflicted with other changes that
110-
have been made since then. You can tell that this happened because you'll see
91+
changes and execute `git rebase master`.
92+
93+
When you rebase a branch on master, all the changes on your branch are
94+
reapplied to the most recent version of master. In other words, git tries to
95+
pretend that the changes you made to the old version of master were instead
96+
made to the new version of master. During this process, you should expect to
97+
encounter at least one "rebase conflict." This happens when git's attempt to
98+
reapply the changes fails because your changes conflicted with other changes
99+
that have been made. You can tell that this happened because you'll see
111100
lines in the output that look like
112101

113102
```
@@ -140,8 +129,8 @@ around too!
140129
Once you're all done fixing the conflicts, you need to stage the files that had
141130
conflicts in them via `git add`. Afterwards, run `git rebase --continue` to let
142131
git know that you've resolved the conflicts and it should finish the rebase.
143-
Finally, once the rebase has succeeded, you'll want to update the associated
144-
branch on your fork with `git push -f`.
132+
Once the rebase has succeeded, you'll want to update the associated branch on
133+
your fork with `git push -f`.
145134

146135
Note that `git push` will not work properly and say something like this:
147136

@@ -173,17 +162,13 @@ edit the commits that you do not skip, or change the order in which they are
173162
applied.
174163

175164
The other common scenario is if you are asked to or want to "squash" multiple
176-
commits into each other. The most common example of this is likely if you
177-
forgot to run `x.py tidy` before committing. Your PR will need to be revised,
178-
but a single commit at the end with message "fixup tidy issue" is usually
179-
unhelpful, and it is easier for everyone else if you combine that commit with
180-
another that has a more meaningful commit message. In this case, you'll want to
181-
run `git rebase -i HEAD~2` to edit the last two commits and merge them
182-
together. Essentially, this reapplies the last two commits on top of your
183-
current branch; this is of course a no-op, since that is where they are
184-
already. However, by selecting the `-i` option, you give yourself the
185-
opportunity to edit the rebase first, just like before. This way you can
186-
request to have the most recent commit squashed into its parent.
165+
commits into each other. If you PR needs only a minor revision, a single commit
166+
at the end with message "fixup small issue" is usually unhelpful, and it is
167+
easier for everyone if you combine that commit with another that has a more
168+
meaningful commit message. Run `git rebase -i HEAD~2` to edit the last two
169+
commits so you can merge them together. By selecting the `-i` option, you give
170+
yourself the opportunity to edit the rebase, similarly to above. This way you
171+
can request to have the most recent commit squashed into its parent.
187172

188173
## No-Merge Policy
189174

@@ -193,11 +178,10 @@ that merge commits in PRs are not accepted. As a result, if you are running
193178
course, this is not always true; if your merge will just be a fast-forward,
194179
like the merges that `git pull` usually performs, then no merge commit is
195180
created and you have nothing to worry about. Running `git config merge.ff only`
196-
once will prevent the creation of merge commits will help ensure you don't make
197-
a mistake here.
181+
once will ensure that all the merges you perform are of this type, so that you
182+
cannot make a mistake.
198183

199184
There are a number of reasons for this decision and like all others, it is a
200-
tradeoff. The main advantage is the (mostly) linear commit history. This
201-
greatly simplifies bisecting. TODO: There are other advantages to a rebase
202-
workflow, but I would like to focus on the ones that people in the Rust project
203-
consider most relevant, so I'm going to leave this unfinished for now.
185+
tradeoff. The main advantage is the generally linear commit history. This
186+
greatly simplifies bisecting and makes the history and commit log much easier
187+
to follow and understand.

0 commit comments

Comments
 (0)