Skip to content

Commit 6f57b8e

Browse files
committed
Add more rebasing help
1 parent 8b42eb5 commit 6f57b8e

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/git.md

+37-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,22 @@ 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: `git rebase -i origin/master`.
106+
107+
See [Rebasing][#rebasing] for more about rebasing.
108+
96109
### I deleted my fork on GitHub!
97110

98111
This is not a problem from git's perspective. If you run `git remote -v`,
@@ -114,6 +127,28 @@ git remote set-url personal <URL>
114127

115128
where the `<URL>` is your new fork.
116129

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

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

0 commit comments

Comments
 (0)