@@ -73,6 +73,30 @@ the same, with some steps skipped:
73
73
2 . Make, stage, and commit your additional changes just like before.
74
74
3 . Push those changes to your fork: ` git push ` .
75
75
76
+ ### Quick note about submodules
77
+
78
+ When updating your local repository with ` git pull ` , you may notice that sometimes
79
+ Git says you have modified some files that you have never edited. For example,
80
+ running ` git status ` gives you something like (note the ` new commits ` mention):
81
+
82
+ ```
83
+ On branch master
84
+ Your branch is up to date with 'origin/master'.
85
+
86
+ Changes not staged for commit:
87
+ (use "git add <file>..." to update what will be committed)
88
+ (use "git restore <file>..." to discard changes in working directory)
89
+ modified: src/tools/cargo (new commits)
90
+ modified: src/tools/rls (new commits)
91
+ modified: src/tools/rustfmt (new commits)
92
+
93
+ no changes added to commit (use "git add" and/or "git commit -a")
94
+ ```
95
+
96
+ These changes are not changes to files: they are changes to submodules
97
+ (more on this later). To get rid of those, run ` git submodule update ` (or run any
98
+ ` x.py ` command which will automatically update the submodules).
99
+
76
100
## Conflicts
77
101
78
102
When you edit your code locally, you are making changes to the version of
@@ -190,3 +214,54 @@ There are a number of reasons for this decision and like all others, it is a
190
214
tradeoff. The main advantage is the generally linear commit history. This
191
215
greatly simplifies bisecting and makes the history and commit log much easier
192
216
to follow and understand.
217
+
218
+ ## Git submodules
219
+
220
+ ** NOTE** : submodules are a nice thing to know about, but it * isn't* an absolute
221
+ prerequisite to contribute to ` rustc ` . If you are using Git for the first time,
222
+ you might want to get used to the main concepts of Git before reading this section.
223
+
224
+ The ` rust-lang/rust ` repository uses [ Git submodules] as a way to use other
225
+ Rust projects from within the ` rust ` repo. Examples include Rust's fork of
226
+ ` llvm-project ` and many devtools such as ` cargo ` , ` rust-analyzer ` and ` rustfmt ` .
227
+
228
+ Those projects are developped and maintained in an separate Git (and GitHub)
229
+ repository, and they have their own Git history/commits, issue tracker and PRs.
230
+ Submodules allow us to create some sort of embedded sub-repository inside the
231
+ ` rust ` repository and use them like they were directories in the ` rust ` repository.
232
+
233
+ Take ` miri ` for example. ` miri ` is maintained in the [ ` rust-lang/miri ` ] repository,
234
+ but it is used in ` rust-lang/rust ` by the compiler for const evaluation. We bring it
235
+ in ` rust ` as a submodule, in the ` src/tools/miri ` folder.
236
+
237
+ The contents of submodules are ignored by Git: submodules are in some sense isolated
238
+ from the rest of the repository. However, if you try to ` cd src/tools/miri ` and then
239
+ run ` git status ` :
240
+
241
+ ```
242
+ HEAD detached at 3fafb835
243
+ nothing to commit, working tree clean
244
+ ```
245
+
246
+ As far as git is concerned, you are no longer in the ` rust ` repo, but in the ` miri ` repo.
247
+ You will notice that we are in "detatched HEAD" state, i.e. not on a branch but on a
248
+ particular commit.
249
+
250
+ This is because, like any dependency, we want to be able to control which version to use.
251
+ Submodules allow us to do just that: every submodule is "pinned" to a certain
252
+ commit, which doesn't change unless modified manually. If you use ` git checkout <commit> `
253
+ in the ` miri ` directory and go back to the ` rust ` directory, you can stage this
254
+ change like any
255
+ This is usually done by
256
+ the maintainers of the project, and looks like [ this] [ miri-update ] .
257
+
258
+ Git submodules take some time to get used to, so don't worry if it isn't perfectly
259
+ clear yet. You will rarely have to use them directly and, again, you don't need
260
+ to know everything about submodules to contribute to Rust. Just know that they
261
+ exist and that they correspond to some sort of embedded subrepository dependency
262
+ that Git can nicely and fairly conveniently handle for us.
263
+
264
+ [ Git submodules ] : https://git-scm.com/book/en/v2/Git-Tools-Submodules
265
+ [ `rust-toolstate` ] : https://rust-lang-nursery.github.io/rust-toolstate/
266
+ [ `rust-lang/miri` ] : https://github.com/rust-lang/miri
267
+ [ miri-update ] : https://github.com/rust-lang/rust/pull/77500/files
0 commit comments