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.
This commit is contained in:
parent
7fdae85e96
commit
fb23f10071
|
|
@ -31,9 +31,9 @@
|
||||||
|
|
||||||
- [Introduction](./contributing.md)
|
- [Introduction](./contributing.md)
|
||||||
- [About the compiler team](./compiler-team.md)
|
- [About the compiler team](./compiler-team.md)
|
||||||
|
- [Using git](./git.md)
|
||||||
- [Mastering @rustbot](./rustbot.md)
|
- [Mastering @rustbot](./rustbot.md)
|
||||||
- [Walkthrough: a typical contribution](./walkthrough.md)
|
- [Walkthrough: a typical contribution](./walkthrough.md)
|
||||||
- [Using git](./git.md)
|
|
||||||
- [Bug Fix Procedure](./bug-fix-procedure.md)
|
- [Bug Fix Procedure](./bug-fix-procedure.md)
|
||||||
- [Implementing new features](./implementing_new_features.md)
|
- [Implementing new features](./implementing_new_features.md)
|
||||||
- [Stability attributes](./stability.md)
|
- [Stability attributes](./stability.md)
|
||||||
|
|
|
||||||
84
src/git.md
84
src/git.md
|
|
@ -8,25 +8,21 @@ can be incorporated into the compiler.
|
||||||
|
|
||||||
The goal of this page is to cover some of the more common questions and
|
The goal of this page is to cover some of the more common questions and
|
||||||
problems new contributors face. Although some git basics will be covered here,
|
problems new contributors face. Although some git basics will be covered here,
|
||||||
if you have never used git or GitHub before you may find that this is still a
|
if you find that this is still a little too fast for you, it might make sense
|
||||||
little too fast for you. In that case, it would make sense to first read some
|
to first read some introductions to git, such as the Beginner and Getting
|
||||||
introductions to git, such as the Beginner and Getting started sections of
|
started sections of [this tutorial from Atlassian][atlassian-git]. GitHub also
|
||||||
[this tutorial from Atlassian][atlassian-git]. GitHub also provides
|
provides [documentation] and [guides] for beginners, or you can consult the
|
||||||
[documentation] and [guides] for beginners.
|
more in depth [book from git].
|
||||||
|
|
||||||
|
[book from git]: https://git-scm.com/book/en/v2/
|
||||||
[atlassian-git]: https://www.atlassian.com/git/tutorials/what-is-version-control
|
[atlassian-git]: https://www.atlassian.com/git/tutorials/what-is-version-control
|
||||||
[documentation]: https://docs.github.com/en/github/getting-started-with-github/set-up-git
|
[documentation]: https://docs.github.com/en/github/getting-started-with-github/set-up-git
|
||||||
[guides]: https://guides.github.com/introduction/git-handbook/
|
[guides]: https://guides.github.com/introduction/git-handbook/
|
||||||
|
|
||||||
Although this page should get you to a point where you can start contributing,
|
|
||||||
learning more git is almost certainly a good use of your time if you want to
|
|
||||||
keep contributing. There are many tutorials online for those folks that are
|
|
||||||
newer which combine excellently with man pages and official documentation.
|
|
||||||
|
|
||||||
## Prequisites
|
## Prequisites
|
||||||
|
|
||||||
We'll assume that you've installed git, forked [rust-lang/rust], and cloned the
|
We'll assume that you've installed git, forked [rust-lang/rust], and cloned the
|
||||||
forked repo to your PC. We'll also use the command line interface to interact
|
forked repo to your PC. We'll use the command line interface to interact
|
||||||
with git; there are also a number of GUIs and IDE integrations that can
|
with git; there are also a number of GUIs and IDE integrations that can
|
||||||
generally do the same things.
|
generally do the same things.
|
||||||
|
|
||||||
|
|
@ -80,34 +76,27 @@ the same, with some steps skipped:
|
||||||
## Conflicts
|
## Conflicts
|
||||||
|
|
||||||
When you edit your code locally, you are making changes to the version of
|
When you edit your code locally, you are making changes to the version of
|
||||||
rust-lang/rust that existed the last time you ran `git pull rust master` on
|
rust-lang/rust that existed when you created your feature branch. As such, when
|
||||||
your master branch. As such, when you submit your PR it is possible that some
|
you submit your PR it is possible that some of the changes that have been made
|
||||||
of the changes that have been made to rust-lang/rust since then are in conflict
|
to rust-lang/rust since then are in conflict with the changes you've made.
|
||||||
with the changes you've made; maybe someone else changed the same lines of
|
|
||||||
code, or git cannot figure out how to merge your changes with the others for
|
|
||||||
another reason.
|
|
||||||
|
|
||||||
When this happens, you need to resolve the conflicts before your changes can be
|
When this happens, you need to resolve the conflicts before your changes can be
|
||||||
merged. First, get a local copy of the conflicting changes. Checkout your local
|
merged. First, get a local copy of the conflicting changes: Checkout your local
|
||||||
master branch with `git checkout master`. Then, `git pull rust master` to
|
master branch with `git checkout master`, then `git pull rust master` to
|
||||||
update it with the most recent changes.
|
update it with the most recent changes.
|
||||||
|
|
||||||
### Rebasing
|
### Rebasing
|
||||||
|
|
||||||
You're now ready to start the rebasing process. Check out the branch with your
|
You're now ready to start the rebasing process. Check out the branch with your
|
||||||
changes, and then execute `git rebase master`.
|
changes and execute `git rebase master`.
|
||||||
|
|
||||||
First, a little background: In git, commits are stored as "diffs" which are a
|
When you rebase a branch on master, all the changes on your branch are
|
||||||
record of all the changes that a commit made to its parent. When you rebase a
|
reapplied to the most recent version of master. In other words, git tries to
|
||||||
branch, all the changes in the commits on that branch are reapplied on the
|
pretend that the changes you made to the old version of master were instead
|
||||||
branch you are rebasing on top of (in this case master). In other words, git
|
made to the new version of master. During this process, you should expect to
|
||||||
tries to pretend that the changes you made to the old version of master were
|
encounter at least one "rebase conflict." This happens when git's attempt to
|
||||||
instead made to the new version of master.
|
reapply the changes fails because your changes conflicted with other changes
|
||||||
|
that have been made. You can tell that this happened because you'll see
|
||||||
During rebasing, you should expect to encounter at least one "rebase conflict."
|
|
||||||
This happens when git's attempt to reapply the changes onto the more recent
|
|
||||||
version of master fails because your changes conflicted with other changes that
|
|
||||||
have been made since then. You can tell that this happened because you'll see
|
|
||||||
lines in the output that look like
|
lines in the output that look like
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
@ -140,8 +129,8 @@ around too!
|
||||||
Once you're all done fixing the conflicts, you need to stage the files that had
|
Once you're all done fixing the conflicts, you need to stage the files that had
|
||||||
conflicts in them via `git add`. Afterwards, run `git rebase --continue` to let
|
conflicts in them via `git add`. Afterwards, run `git rebase --continue` to let
|
||||||
git know that you've resolved the conflicts and it should finish the rebase.
|
git know that you've resolved the conflicts and it should finish the rebase.
|
||||||
Finally, once the rebase has succeeded, you'll want to update the associated
|
Once the rebase has succeeded, you'll want to update the associated branch on
|
||||||
branch on your fork with `git push -f`.
|
your fork with `git push -f`.
|
||||||
|
|
||||||
Note that `git push` will not work properly and say something like this:
|
Note that `git push` will not work properly and say something like this:
|
||||||
|
|
||||||
|
|
@ -173,17 +162,13 @@ edit the commits that you do not skip, or change the order in which they are
|
||||||
applied.
|
applied.
|
||||||
|
|
||||||
The other common scenario is if you are asked to or want to "squash" multiple
|
The other common scenario is if you are asked to or want to "squash" multiple
|
||||||
commits into each other. The most common example of this is likely if you
|
commits into each other. If you PR needs only a minor revision, a single commit
|
||||||
forgot to run `x.py tidy` before committing. Your PR will need to be revised,
|
at the end with message "fixup small issue" is usually unhelpful, and it is
|
||||||
but a single commit at the end with message "fixup tidy issue" is usually
|
easier for everyone if you combine that commit with another that has a more
|
||||||
unhelpful, and it is easier for everyone else if you combine that commit with
|
meaningful commit message. Run `git rebase -i HEAD~2` to edit the last two
|
||||||
another that has a more meaningful commit message. In this case, you'll want to
|
commits so you can merge them together. By selecting the `-i` option, you give
|
||||||
run `git rebase -i HEAD~2` to edit the last two commits and merge them
|
yourself the opportunity to edit the rebase, similarly to above. This way you
|
||||||
together. Essentially, this reapplies the last two commits on top of your
|
can request to have the most recent commit squashed into its parent.
|
||||||
current branch; this is of course a no-op, since that is where they are
|
|
||||||
already. However, by selecting the `-i` option, you give yourself the
|
|
||||||
opportunity to edit the rebase first, just like before. This way you can
|
|
||||||
request to have the most recent commit squashed into its parent.
|
|
||||||
|
|
||||||
## No-Merge Policy
|
## No-Merge Policy
|
||||||
|
|
||||||
|
|
@ -193,11 +178,10 @@ that merge commits in PRs are not accepted. As a result, if you are running
|
||||||
course, this is not always true; if your merge will just be a fast-forward,
|
course, this is not always true; if your merge will just be a fast-forward,
|
||||||
like the merges that `git pull` usually performs, then no merge commit is
|
like the merges that `git pull` usually performs, then no merge commit is
|
||||||
created and you have nothing to worry about. Running `git config merge.ff only`
|
created and you have nothing to worry about. Running `git config merge.ff only`
|
||||||
once will prevent the creation of merge commits will help ensure you don't make
|
once will ensure that all the merges you perform are of this type, so that you
|
||||||
a mistake here.
|
cannot make a mistake.
|
||||||
|
|
||||||
There are a number of reasons for this decision and like all others, it is a
|
There are a number of reasons for this decision and like all others, it is a
|
||||||
tradeoff. The main advantage is the (mostly) linear commit history. This
|
tradeoff. The main advantage is the generally linear commit history. This
|
||||||
greatly simplifies bisecting. TODO: There are other advantages to a rebase
|
greatly simplifies bisecting and makes the history and commit log much easier
|
||||||
workflow, but I would like to focus on the ones that people in the Rust project
|
to follow and understand.
|
||||||
consider most relevant, so I'm going to leave this unfinished for now.
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue