Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add help for when you update a submodule by accident #1537

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@ git remote set-url origin <URL>

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

### I changed a submodule by accident

Usually people notice this when rustbot posts a comment on github that `cargo` has been modified:

![rustbot submodule comment](./img/rustbot-submodules.png)

You might also notice conflicts in the web UI:

![conflict in src/tools/cargo](./img/submodule-conflicts.png)
Copy link
Member

@chenyukang chenyukang Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyn514
I was annoyed by this for some time, now I use this justfile for just to rebase or sync master:

old_branch := `git rev-parse --abbrev-ref HEAD`
rebm:
        git stash
        git checkout up-master
        git pull
        git submodule sync
        git submodule update
        git stash
        git checkout {{old_branch}}
        git rebase up-master

sync:
        git stash
        git checkout up-master
        git pull
        git submodule sync
        git submodule update

Then only run j rebm to to rebase master.
I'm not sure whether we can provide some handy functions to help developers, but I'm sure for those devs who don't touch submodules, it will save a lot of time to fix submodule conflicts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving comments on closed PRs is not a good way to contact me, I have too many github notifications to read them all.

It sounds like you have a suggestion to improve this section :) feel free to open either an issue or a PR.


The most common cause is that you rebased after a change and ran `git add .` without first running
`x.py` 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:
Expand Down
Binary file added src/img/rustbot-submodules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/submodule-conflicts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.