Home Explore Blog CI



rustc

3rd chunk of `src/git.md`
fc59dbea764c56e264af945361bc5936e8299fb03f7bdd430000000100000817


The most common cause is that you rebased after a change and ran `git add .` without first running
`x` to update the submodules.  Alternatively, you might have run `cargo fmt` instead of `x fmt`
and modified files in a submodule, then committed the changes.

To fix it, do the following things:

1. See which commit has the accidental changes: `git log --stat -n1 src/tools/cargo`
2. Revert the changes to that commit: `git checkout <my-commit>~ src/tools/cargo`. Type `~`
   literally but replace `<my-commit>` with the output from step 1.
3. Tell git to commit the changes: `git commit --fixup <my-commit>`
4. Repeat steps 1-3 for all the submodules you modified.
    - If you modified the submodule in several different commits, you will need to repeat steps 1-3
    for each commit you modified. You'll know when to stop when the `git log` command shows a commit
    that's not authored by you.
5. Squash your changes into the existing commits: `git rebase --autosquash -i upstream/master`
6. [Push your changes](#standard-process).

### I see "error: cannot rebase" when I try to rebase

These are two common errors to see when rebasing:
```console
error: cannot rebase: Your index contains uncommitted changes.
error: Please commit or stash them.
```
```console
error: cannot rebase: You have unstaged changes.
error: Please commit or stash them.
```

(See <https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F#_the_three_states> for the difference between the two.)

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 committed
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:

```console
git config --global rebase.autostash true
```

See <https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning> for more info about stashing.

Title: Fixing Accidental Submodule Changes and Resolving Rebase Errors
Summary
This section provides steps to correct accidental changes in Git submodules, typically indicated by rustbot or UI conflicts, involving identifying the problematic commit, reverting changes, and using `git rebase --autosquash` to integrate fixes. It also addresses common 'cannot rebase' errors due to uncommitted or unstaged changes, recommending either committing the changes or using Git's stash feature, with an option to configure automatic stashing via `git config --global rebase.autostash true`.