Skip to content

Commit ba1db24

Browse files
committed
Add more rebasing help
1 parent 54e6f5b commit ba1db24

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/git.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ started sections of [this tutorial from Atlassian][atlassian-git]. GitHub also
1616
provides [documentation] and [guides] for beginners, or you can consult the
1717
more in depth [book from Git].
1818

19+
This guide is incomplete. If you run into trouble with git that this page doesn't help with,
20+
please [open an issue] so we can document how to fix it.
21+
22+
[open an issue]: https://github.com/rust-lang/rustc-dev-guide/issues/new
1923
[book from Git]: https://git-scm.com/book/en/v2/
2024
[atlassian-git]: https://www.atlassian.com/git/tutorials/what-is-version-control
2125
[documentation]: https://docs.github.com/en/get-started/quickstart/set-up-git
@@ -58,7 +62,7 @@ and PRs:
5862
1. Ensure that you're making your changes on top of master:
5963
`git checkout master`.
6064
2. Get the latest changes from the Rust repo: `git pull upstream master --ff-only`.
61-
(see [No-Merge Policy](#keeping-things-up-to-date) for more info about this).
65+
(see [No-Merge Policy][no-merge-policy] for more info about this).
6266
3. Make a new branch for your change: `git checkout -b issue-12345-fix`.
6367
4. Make some changes to the repo and test them.
6468
5. Stage your changes via `git add src/changed/file.rs src/another/change.rs`
@@ -76,7 +80,7 @@ pulling-and-rebasing, you can use `git push --force-with-lease`).
7680

7781
If you end up needing to rebase and are hitting conflicts, see [Rebasing](#rebasing).
7882
If you want to track upstream while working on long-running feature/issue, see
79-
[Keeping things up to date](#keeping-things-up-to-date).
83+
[Keeping things up to date][no-merge-policy].
8084

8185
If your reviewer requests changes, the procedure for those changes looks much
8286
the same, with some steps skipped:
@@ -86,13 +90,23 @@ the same, with some steps skipped:
8690
2. Make, stage, and commit your additional changes just like before.
8791
3. Push those changes to your fork: `git push`.
8892

93+
[no-merge-policy]: #keeping-things-up-to-date
94+
8995
## Troubleshooting git issues
9096

9197
You don't need to clone `rust-lang/rust` from scratch if it's out of date!
9298
Even if you think you've messed it up beyond repair, there are ways to fix
9399
the git state that don't require downloading the whole repository again.
94100
Here are some common issues you might run into:
95101

102+
### I made a merge commit by accident.
103+
104+
Git has two ways to update your branch with the newest changes: merging and rebasing.
105+
Rust [uses rebasing][no-merge-policy]. If you make a merge commit, it's not too hard to fix:
106+
`git rebase -i origin/master`.
107+
108+
See [Rebasing][#rebasing] for more about rebasing.
109+
96110
### I deleted my fork on GitHub!
97111

98112
This is not a problem from git's perspective. If you run `git remote -v`,
@@ -114,6 +128,31 @@ git remote set-url personal <URL>
114128

115129
where the `<URL>` is your new fork.
116130

131+
### I see "error: cannot rebase" when I try to rebase
132+
133+
These are two common errors to see when rebasing:
134+
```
135+
error: cannot rebase: Your index contains uncommitted changes.
136+
error: Please commit or stash them.
137+
```
138+
```
139+
error: cannot rebase: You have unstaged changes.
140+
error: Please commit or stash them.
141+
```
142+
143+
(See https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F#_the_three_states for the difference between the two.)
144+
145+
This means you have made changes since the last time you made a commit. To be able to rebase, either
146+
commit your changes, or make a temporary commit called a "stash" to have them still not be commited
147+
when you finish rebasing. You may want to configure git to make this "stash" automatically, which
148+
will prevent the "cannot rebase" error in nearly all cases:
149+
150+
```
151+
git config --global rebase.autostash true
152+
```
153+
154+
See https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning for more info about stashing.
155+
117156
### I see 'Untracked Files: src/stdarch'?
118157

119158
This is left over from the move to the `library/` directory.

0 commit comments

Comments
 (0)