Skip to content

Commit 49ac43f

Browse files
committed
Incorporated suggestions into git page and edit for more brevity.
The Advanced Rebasing section has been mostly rewritten to include both a major suggestion from jyn and a general rewrite.
1 parent 360d4a5 commit 49ac43f

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/git.md

+30-26
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ and PRs:
6060
unintentionally commit changes that should not be committed, such as submodule
6161
updates. You can use `git status` to check if there are any files you forgot
6262
to stage.
63-
6. Push your changes to your fork: `git push -u origin issue-12345-fix`.
63+
6. Push your changes to your fork: `git push --set-upstream origin issue-12345-fix`.
6464
7. [Open a PR][ghpullrequest] from your fork to rust-lang/rust's master branch.
6565

6666
[ghpullrequest]: https://guides.github.com/activities/forking/#making-a-pull-request
@@ -119,18 +119,18 @@ master, while the other side has your version of the code. You'll need to
119119
decide how to deal with the conflict. You may want to keep your changes,
120120
keep the changes on master, or combine the two.
121121

122-
Generally, resovling the conflict consists of two steps: First, fix the
122+
Generally, resolving the conflict consists of two steps: First, fix the
123123
particular conflict. Edit the file to make the changes you want and remove the
124124
`<<<<<<<`, `=======` and `>>>>>>>` lines in the process. Second, check the
125-
surrounding code. If there was a conflict, its because someone else changed the
126-
same code you did. That means its likely there are some logical errors lying
127-
around too!
125+
surrounding code. If there was a conflict, its likely there are some logical
126+
errors lying around too! It's a good idea to run `x.py check` here to make sure
127+
there are no glaring errors.
128128

129129
Once you're all done fixing the conflicts, you need to stage the files that had
130130
conflicts in them via `git add`. Afterwards, run `git rebase --continue` to let
131131
git know that you've resolved the conflicts and it should finish the rebase.
132132
Once the rebase has succeeded, you'll want to update the associated branch on
133-
your fork with `git push -f`.
133+
your fork with `git push --force`.
134134

135135
Note that `git push` will not work properly and say something like this:
136136

@@ -145,30 +145,34 @@ hint: See the 'Note about fast-forwards' in 'git push --help' for details.
145145

146146
The advice this gives is incorrect! Because of the "no-merge" policy, running
147147
`git pull` will create a merge commit, defeating the point of your rebase. Use
148-
`git push -f` instead.
148+
`git push --force` instead.
149149

150150
## Advanced Rebasing
151151

152-
Sometimes, you may want to perform a more complicated rebase. There are two
153-
common scenarios that might call for this.
154-
155152
If your branch contains multiple consecutive rewrites of the same code, or if
156-
the rebase conflicts are extremely severe, it is possible that just trying to
157-
reapply the changes you made on top of the updated code will be too much of a
158-
headache. In this case, you can use the interactive rebase feature via
159-
`git rebase -i master` to gain more control over the process. This allows you
160-
to choose to skip commits because they represent changes you no longer need,
161-
edit the commits that you do not skip, or change the order in which they are
162-
applied.
163-
164-
The other common scenario is if you are asked to or want to "squash" multiple
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.
153+
the rebase conflicts are extremely severe, you can use
154+
`git rebase --interactive master` to gain more control over the process. This
155+
allows you to choose to skip commits, edit the commits that you do not skip,
156+
change the order in which they are applied, or "squash" them into each other.
157+
158+
Alternatively, you can sacrifice the commit history like this:
159+
160+
```
161+
# squash all the changes into one commit so you only have to worry about conflicts once
162+
git rebase -i $(git merge-base master) # and squash all changes along the way
163+
git rebase master
164+
# fix all merge conflicts
165+
git rebase --continue
166+
```
167+
168+
"Squashing" commits into each other causes them to be merged into a single
169+
commit. Both the upside and downside of this is that it simplifies the history.
170+
On the one hand, you lose track of the steps in which changes were made, but
171+
the history becomes easier to work with.
172+
173+
You also may want to squash just the last few commits together, possibly
174+
because they only represent "fixups" and not real changes.
175+
`git rebase --interactive HEAD~2` will allow you to edit the two commits only.
172176

173177
## No-Merge Policy
174178

0 commit comments

Comments
 (0)