Skip to content

Commit 374c092

Browse files
committed
Give help for when you update a submodule by accident
1 parent 586474f commit 374c092

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/git.md

+23
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,29 @@ git remote set-url origin <URL>
128128

129129
where the `<URL>` is your new fork.
130130

131+
### I changed a submodule by accident
132+
133+
Usually people first notice this when rustbot posts a comment on github that `cargo` has been modified:
134+
135+
![rustbot submodule comment](./img/rustbot-submodules.png)
136+
137+
You might also notice conflicts in the web UI:
138+
139+
![conflict in src/tools/cargo](./img/submodule-conflicts.png)
140+
141+
The most common cause is that you rebased after a chance and ran `git add .` without first running `x.py` to update the submodules.
142+
Alternatively, you might have run `cargo fmt` instead of `x fmt` and modified files in a submodule, then commited the changes.
143+
144+
To fix it, do the following things:
145+
146+
1. See which commit has the accidental changes: `git log --stat -n1 src/tools/cargo`
147+
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.
148+
3. Tell git to commit the changes: `git commit --fixup <my-commit>`
149+
4. Repeat steps 1-3 for all the submodules you modified.
150+
- 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.
151+
5. Squash your changes into the existing commits: `git rebase --autosquash -i upstream/master`
152+
6. [Push your changes](#standard-process).
153+
131154
### I see "error: cannot rebase" when I try to rebase
132155

133156
These are two common errors to see when rebasing:

src/img/rustbot-submodules.png

25.4 KB
Loading

src/img/submodule-conflicts.png

19.7 KB
Loading

0 commit comments

Comments
 (0)