Skip to content

Commit 705d020

Browse files
authored
Merged commits to english repo up to the 15.10.2019 (#30)
* Added last commits from the main english repos except the one with the svg files * Added commits from the main english repo up to the 15.10.2019
1 parent 485cac9 commit 705d020

File tree

6 files changed

+1385
-226
lines changed

6 files changed

+1385
-226
lines changed

book/01-introduction/sections/help.asc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Diese Befehle sind nützlich, weil Sie sich die Hilfe jederzeit anzeigen lassen
2121
Wenn die Hilfeseiten und dieses Buch nicht ausreichen und Sie persönliche Hilfe brauchen, können Sie den `#git` oder `#github` Kanal auf dem Freenode IRC Server probieren, der unter https://freenode.net zu finden ist.
2222
Diese Kanäle sind in der Regel sehr gut besucht. Normalerweise findet sich unter den vielen Anwendern, die oft sehr viel Erfahrung mit Git haben, irgendjemand, der Ihnen weiterhelfen kann.(((IRC)))
2323

24-
Wenn Sie nicht die vollständige Manpage-Hilfe benötigen, sondern nur eine kurze Beschreibung der verfügbaren Optionen für einen Git-Befehl, können Sie auch in den kompakteren „Hilfeseiten“ mit den Optionen `-h` oder `--help` nachschauen, wie in:
24+
Wenn Sie nicht die vollständige Manpage-Hilfe benötigen, sondern nur eine kurze Beschreibung der verfügbaren Optionen für einen Git-Befehl, können Sie auch in den kompakteren „Hilfeseiten“ mit der `-h` Option nachschauen, wie in:
2525

2626
[source,console]
2727
----

book/07-git-tools/sections/submodules.asc

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Submodule path 'DbConnector': checked out 'c3f01dc8862123d317dd46284b05b6892c7b2
185185
Now your `DbConnector` subdirectory is at the exact state it was in when you committed earlier.
186186

187187
There is another way to do this which is a little simpler, however.
188-
If you pass `--recurse-submodules` to the `git clone` command, it will automatically initialize and update each submodule in the repository.
188+
If you pass `--recurse-submodules` to the `git clone` command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.
189189

190190
[source,console]
191191
----
@@ -206,11 +206,14 @@ Checking connectivity... done.
206206
Submodule path 'DbConnector': checked out 'c3f01dc8862123d317dd46284b05b6892c7b29bc'
207207
----
208208

209+
If you already cloned the project and forgot `--recurse-submodules`, you can combine the `git submodule init` and `git submodule update` steps by running `git submodule update --init`.
210+
To also initialize, fetch and checkout any nested submodules, you can use the foolproof `git submodule update --init --recursive`.
211+
209212
==== Working on a Project with Submodules
210213

211214
Now we have a copy of a project with submodules in it and will collaborate with our teammates on both the main project and the submodule project.
212215

213-
===== Pulling in Upstream Changes
216+
===== Pulling in Upstream Changes from the Submodule Remote
214217

215218
The simplest model of using submodules in a project would be if you were simply consuming a subproject and wanted to get updates from it from time to time but were not actually modifying anything in your checkout.
216219
Let's walk through a simple example there.
@@ -372,6 +375,68 @@ Submodule DbConnector c3f01dc..c87d55d:
372375

373376
Git will by default try to update *all* of your submodules when you run `git submodule update --remote` so if you have a lot of them, you may want to pass the name of just the submodule you want to try to update.
374377

378+
===== Pulling Upstream Changes from the Project Remote
379+
Let's now step into the shoes of your collaborator, who has his own local clone of the the MainProject repository.
380+
Simply executing `git pull` to get your newly committed changes is not enough:
381+
382+
[source,console]
383+
----
384+
$ git pull
385+
From https://github.com/chaconinc/MainProject
386+
fb9093c..0a24cfc master -> origin/master
387+
Fetching submodule DbConnector
388+
From https://github.com/chaconinc/DbConnector
389+
c3f01dc..c87d55d stable -> origin/stable
390+
Updating fb9093c..0a24cfc
391+
Fast-forward
392+
.gitmodules | 2 +-
393+
DbConnector | 2 +-
394+
2 files changed, 2 insertions(+), 2 deletions(-)
395+
396+
$ git status
397+
On branch master
398+
Your branch is up-to-date with 'origin/master'.
399+
Changes not staged for commit:
400+
(use "git add <file>..." to update what will be committed)
401+
(use "git checkout -- <file>..." to discard changes in working directory)
402+
403+
modified: DbConnector (new commits)
404+
405+
Submodules changed but not updated:
406+
407+
* DbConnector c87d55d...c3f01dc (4):
408+
< catch non-null terminated lines
409+
< more robust error handling
410+
< more efficient db routine
411+
< better connection routine
412+
413+
no changes added to commit (use "git add" and/or "git commit -a")
414+
----
415+
416+
By default, the `git pull` command recursively fetches submodules changes, as we can see in the output of the first command above.
417+
However, it does not *update* the submodules.
418+
This is shown by the output of the `git status` command, which shows the submodule is ``modified'', and has ``new commits''.
419+
What's more, the brackets showing the new commits point left (<), indicating that these commits are recorded in MainProject but are not present in the local DbConnector checkout.
420+
To finalize the update, you need to run `git submodule update`:
421+
422+
[source,console]
423+
----
424+
$ git submodule update --init --recursive
425+
Submodule path 'vendor/plugins/demo': checked out '48679c6302815f6c76f1fe30625d795d9e55fc56'
426+
427+
$ git status
428+
On branch master
429+
Your branch is up-to-date with 'origin/master'.
430+
nothing to commit, working tree clean
431+
----
432+
433+
Note that to be on the safe side, you should run `git submodule update` with the `--init` flag in case the MainProject commits you just pulled added new submodules, and with the `--recursive` flag if any submodules have nested submodules.
434+
435+
If you want to automate this process, you can add the `--recurse-submodules` flag to the `git pull` command (since Git 2.14).
436+
This will make Git run `git submodule update` right after the pull, putting the submodules in the correct state.
437+
Moreover, if you want to make Git always pull with `--recurse-submodules`, you can set the configuration option `submodule.recurse` to true (this works for `git pull` since Git 2.15).
438+
This option will make Git use the `--recurse-submodules` flag for all commands that support it (except `clone`).
439+
375440
===== Working on a Submodule
376441

377442
It's quite likely that if you're using submodules, you're doing so because you really want to work on the code in the submodule at the same time as you're working on the code in the main project (or across several submodules).
@@ -393,16 +458,18 @@ First of all, let's go into our submodule directory and check out a branch.
393458

394459
[source,console]
395460
----
461+
$ cd DbConnector/
396462
$ git checkout stable
397463
Switched to branch 'stable'
398464
----
399465

400-
Let's try it with the ``merge'' option.
466+
Let's try updating our submodule with the ``merge'' option.
401467
To specify it manually, we can just add the `--merge` option to our `update` call.
402468
Here we'll see that there was a change on the server for this submodule and it gets merged in.
403469

404470
[source,console]
405471
----
472+
$ cd ..
406473
$ git submodule update --remote --merge
407474
remote: Counting objects: 4, done.
408475
remote: Compressing objects: 100% (2/2), done.
@@ -433,6 +500,7 @@ Now if we update our submodule we can see what happens when we have made a local
433500

434501
[source,console]
435502
----
503+
$ cd ..
436504
$ git submodule update --remote --rebase
437505
First, rewinding head to replay your work on top of it...
438506
Applying: unicode support
@@ -793,11 +861,16 @@ This way you can simply run `git supdate` when you want to update your submodule
793861

794862
Using submodules isn't without hiccups, however.
795863

796-
For instance switching branches with submodules in them can also be tricky.
864+
===== Switching branches
865+
866+
For instance, switching branches with submodules in them can also be tricky with Git versions older than Git 2.13.
797867
If you create a new branch, add a submodule there, and then switch back to a branch without that submodule, you still have the submodule directory as an untracked directory:
798868

799869
[source,console]
800870
----
871+
$ git --version
872+
git version 2.12.2
873+
801874
$ git checkout -b add-crypto
802875
Switched to a new branch 'add-crypto'
803876
@@ -849,6 +922,47 @@ Makefile includes scripts src
849922

850923
Again, not really very difficult, but it can be a little confusing.
851924

925+
Newer Git versions (Git >= 2.13) simplify all this by adding the `--recurse-submodules` flag to the `git checkout` command, which takes care of placing the submodules in the right state for the branch we are switching to.
926+
927+
[source,console]
928+
----
929+
$ git --version
930+
git version 2.13.3
931+
932+
$ git checkout -b add-crypto
933+
Switched to a new branch 'add-crypto'
934+
935+
$ git submodule add https://github.com/chaconinc/CryptoLibrary
936+
Cloning into 'CryptoLibrary'...
937+
...
938+
939+
$ git commit -am 'adding crypto library'
940+
[add-crypto 4445836] adding crypto library
941+
2 files changed, 4 insertions(+)
942+
create mode 160000 CryptoLibrary
943+
944+
$ git checkout --recurse-submodules master
945+
Switched to branch 'master'
946+
Your branch is up-to-date with 'origin/master'.
947+
948+
$ git status
949+
On branch master
950+
Your branch is up-to-date with 'origin/master'.
951+
952+
nothing to commit, working tree clean
953+
----
954+
955+
Using the the `--recurse-submodules` flag of `git checkout` can also be useful when you work on several branches in the superproject, each having your submodule pointing at different commits.
956+
Indeed, if you switch between branches that record the submodule at different commits, upon executing `git status` the submodule will appear as ``modified'', and indicate ``new commits''. That is because the submodule state is by default not carried over when switching branches.
957+
958+
This can be really confusing, so it's a good idea to always `git checkout --recurse-submodules` when your project has submodules.
959+
(For older Git versions that do not have the `--recurse-submodules` flag, after the checkout you can use `git submodule update --init --recursive` to put the submodules in the right state.)
960+
961+
Luckily, you can tell Git (>=2.14) to always use the `--recurse-submodules` flag by setting the configuration option `submodule.recurse`: `git config submodule.recurse true`.
962+
As noted above, this will also make Git recurse into submodules for every command that has a `--recurse-submodules` option (except `git clone`).
963+
964+
===== Switching from subdirectories to submodules
965+
852966
The other main caveat that many people run into involves switching from subdirectories to submodules.
853967
If you've been tracking files in your project and you want to move them out into a submodule, you must be careful or Git will get angry at you.
854968
Assume that you have files in a subdirectory of your project, and you want to switch it to a submodule.

book/B-embedding-git/sections/libgit2.asc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ error = git_odb_add_backend(odb, my_backend, 1); // <3>
131131
132132
git_repository *repo;
133133
error = git_repository_open(&repo, "some-path");
134-
error = git_repository_set_odb(odb); // <4>
134+
error = git_repository_set_odb(repo, odb); // <4>
135135
----
136136

137137
_(Note that errors are captured, but not handled. We hope your code is better than ours.)_

0 commit comments

Comments
 (0)