You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/07-git-tools/sections/searching.asc
+31-31Lines changed: 31 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
[[_searching]]
2
-
=== Searching
2
+
=== Suchen
3
3
4
-
With just about any size codebase, you'll often need to find where a function is called or defined, or display the history of a method.
5
-
Git provides a couple of useful tools for looking through the code and commits stored in its database quickly and easily.
6
-
We'll go through a few of them.
4
+
Bei fast jeder Codebasis müssen Sie oft herausfinden, wo eine Funktion aufgerufen oder definiert wird, oder die Historie einer Methode anzeigen.
5
+
Git bietet eine Reihe nützlicher Werkzeuge, um den Code und die in seiner Datenbank gespeicherten Commits schnell und einfach durchzusehen.
6
+
Im Folgenden gehen wir ein paar davon durch.
7
7
8
8
[[_git_grep]]
9
9
==== Git Grep
10
10
11
-
Git ships with a command called `grep` that allows you to easily search through any committed tree, the working directory, or even the index for a string or regular expression.
12
-
For the examples that follow, we'll search through the source code for Git itself.
11
+
Git wird mit einem Befehl namens `grep` ausgeliefert, der es Ihnen ermöglicht, auf einfache Weise einen beliebigen Verzeichnisbaum, das Arbeitsverzeichnis oder sogar die Staging-Area nach einer Zeichenkette (engl. string) oder einem regulären Ausdruck (engl. regular expression) zu durchsuchen.
12
+
Für die folgenden Beispiele werden wir den Quellcode von Git selbst durchsuchen.
13
13
14
-
By default, `git grep` will look through the files in your working directory.
15
-
As a first variation, you can use either of the `-n` or `--line-number` options to print out the line numbers where Git has found matches:
14
+
Standardmäßig durchsucht `git grep` die Dateien in Ihrem Arbeitsverzeichnis.
15
+
Als erste Variante können Sie eine der Optionen `-n` oder `--line-number` verwenden, um die Zeilennummern anzuzeigen, bei denen Git Übereinstimmungen gefunden hat:
In addition to the basic search shown above, `git grep` supports a plethora of other interesting options.
33
+
Zusätzlich zur oben gezeigten einfachen Suche unterstützt `git grep` eine Vielzahl weiterer interessanter Optionen.
34
34
35
-
For instance, instead of printing all of the matches, you can ask `git grep` to summarize the output by showing you only which files contained the search string and how many matches there were in each file with the `-c` or `--count` option:
35
+
Anstatt beispielsweise alle Übereinstimmungen anzuzeigen, können Sie die Ausgabe von `git grep` mit der Option `-c` oder `--count` zusammenfassen: es zeigt Ihnen dann nur an, welche Dateien den Suchbegriff enthalten und wie viele Übereinstimmungen es in jeder Datei gibt:
36
36
37
37
[source,console]
38
38
----
@@ -44,7 +44,7 @@ date.c:3
44
44
git-compat-util.h:2
45
45
----
46
46
47
-
If you're interested in the _context_ of a search string, you can display the enclosing method or function for each matching string with either of the `-p` or `--show-function` options:
47
+
Wenn Sie sich für den _Kontext_ eines Suchbegriffs interessieren, können Sie die umschließende Methode oder Funktion für jeden passenden Suchbegriff mit einer der Optionen `-p` oder `--show-function` anzeigen:
date.c: /* gmtime_r() in match_digit() may have clobbered it */
58
58
----
59
59
60
-
As you can see, the `gmtime_r` routine is called from both the `match_multi_number` and `match_digit` functions in the `date.c` file (the third match displayed represents just the string appearing in a comment).
60
+
Wie Sie sehen können, wird die Routine `gmtime_r` sowohl von den Funktionen `match_multi_number` als auch `match_digit` in der Datei `date.c` aufgerufen (die dritte angezeigte Übereinstimmung stellt nur den String dar, der in einem Kommentar erscheint).
61
61
62
-
You can also search for complex combinations of strings with the `--and` flag, which ensures that multiple matches must occur in the same line of text.
63
-
For instance, let's look for any lines that define a constant whose name contains _either_ of the substrings ``LINK'' or ``BUF_MAX'', specifically in an older version of the Git codebase represented by the tag `v1.8.0` (we'll throw in the `--break` and `--heading` options which help split up the output into a more readable format):
62
+
Sie können mit `--and` nach komplexen Kombinationen von Strings suchen, was sicherstellt, dass mehrere Übereinstimmungen in der gleichen Textzeile vorkommen müssen.
63
+
Suchen wir zum Beispiel nach Zeilen, die eine Konstante definieren (den Teilstring `#define` enthalten), deren Name einen der Teilstrings `LINK` oder `BUF_MAX` enthält. Wir suchen hier in einer älteren Version der Git-Codebasis, die durch den Tag v1.8.0 repräsentiert wird (wir werden die Optionen `--break` und -`-heading` hinzufügen, um die Ausgabe in ein besser lesbares Format aufzuteilen):
The `git grep` command has a few advantages over normal searching commands like `grep` and `ack`.
91
-
The first is that it's really fast, the second is that you can search through any tree in Git, not just the working directory.
92
-
As we saw in the above example, we looked for terms in an older version of the Git source code, not the version that was currently checked out.
90
+
Der Befehl `git grep` hat einige Vorteile gegenüber normalen Suchbefehlen wie `grep` und `ack`.
91
+
Der erste Vorteil ist, dass es sehr schnell ist, der zweite, dass Sie jeden Baum in Git durchsuchen können, nicht nur das Arbeitsverzeichnis.
92
+
Wie wir im obigen Beispiel gesehen haben, haben wir nach Begriffen in einer älteren Version des Git-Quellcodes gesucht, nicht in der Version, die gerade ausgecheckt war.
93
93
94
-
==== Git Log Searching
94
+
==== Stichwortsuche in Git Log
95
95
96
-
Perhaps you're looking not for _where_ a term exists, but _when_ it existed or was introduced.
97
-
The `git log` command has a number of powerful tools for finding specific commits by the content of their messages or even the content of the diff they introduce.
96
+
Vielleicht suchen Sie nicht, _wo_ ein Begriff existiert, sondern _wann_ er existiert oder eingeführt wurde.
97
+
Der Befehl `git log` verfügt über eine Reihe leistungsfähiger Werkzeuge, um bestimmte Commits anhand des Inhalts ihrer Nachrichten, oder sogar anhand des Inhalts des von ihnen eingeführten Diffs zu finden.
98
98
99
-
If, for example, we want to find out when the `ZLIB_BUF_MAX` constant was originally introduced, we can use the `-S` option (colloquially referred to as the Git ``pickaxe'' option) to tell Git to show us only those commits that changed the number of occurrences of that string.
99
+
Wenn wir zum Beispiel herausfinden wollen, wann die Konstante `ZLIB_BUF_MAX` ursprünglich eingeführt wurde, können wir die Option `-S` (umgangssprachlich als Git ``pickaxe'' Option bezeichnet) verwenden, um Git anzuweisen, uns nur die Commits anzuzeigen, in denen die Anzahl der Vorkommen dieses Strings geändert wurde.
100
100
101
101
[source,console]
102
102
----
@@ -105,17 +105,17 @@ e01503b zlib: allow feeding more than 4GB in one go
105
105
ef49a7a zlib: zlib can only process 4GB at a time
106
106
----
107
107
108
-
If we look at the diff of those commits, we can see that in `ef49a7a` the constant was introduced and in `e01503b` it was modified.
108
+
Wenn wir uns den Unterschied dieser Commits ansehen, können wir sehen, dass die Konstante in `ef49a7a` eingeführt und in `e01503b` geändert wurde.
109
109
110
-
If you need to be more specific, you can provide a regular expression to search for with the `-G` option.
110
+
Wenn Sie spezifischer sein wollen, können Sie mit der Option `-G` einen regulären Ausdruck für die Suche angeben.
111
111
112
-
===== Line Log Search
112
+
===== Zeilen- und Funktionssuche in Git Log
113
113
114
-
Another fairly advanced log search that is insanely useful is the line history search.
115
-
Simply run `git log` with the `-L` option, and it will show you the history of a function or line of code in your codebase.
114
+
Eine weitere ziemlich fortgeschrittene Logsuche, die wahnsinnig nützlich ist, ist die Suche nach dem Zeilen- und Funktionsverlauf.
115
+
Führen Sie einfach `git log` mit der Option `-L` aus, und es wird Ihnen die Historie einer Funktion oder Codezeile in Ihrer Codebasis angezeigen.
116
116
117
-
For example, if we wanted to see every change made to the function `git_deflate_bound` in the `zlib.c` file, we could run `git log -L :git_deflate_bound:zlib.c`.
118
-
This will try to figure out what the bounds of that function are and then look through the history and show us every change that was made to the function as a series of patches back to when the function was first created.
117
+
Wenn wir zum Beispiel jede Änderung an der Funktion `git_deflate_bound` in der Datei `zlib.c` sehen wollten, könnten wir `git log -L :git_deflate_bound:zlib.c` ausführen.
118
+
Dies wird versuchen, die Grenzen dieser Funktion herauszufinden und dann die Historie durchzusehen und uns jede Änderung, die an der Funktion vorgenommen wurde, als eine Reihe von Patches bis zum Zeitpunkt der ersten Erstellung der Funktion zu zeigen.
119
119
120
120
[source,console]
121
121
----
@@ -155,6 +155,6 @@ diff --git a/zlib.c b/zlib.c
155
155
+
156
156
----
157
157
158
-
If Git can't figure out how to match a function or method in your programming language, you can also provide it with a regular expression (or _regex_).
159
-
For example, this would have done the same thing as the example above: `git log -L '/unsigned long git_deflate_bound/',/^}/:zlib.c`.
160
-
You could also give it a range of lines or a single line number and you'll get the same sort of output.
158
+
Wenn Git nicht herausfinden kann, wie man eine Funktion oder Methode in Ihrer Programmiersprache abgleicht, können Sie Git auch einen regulären Ausdruck (engl. regular expression oder regex) geben.
159
+
Zum Beispiel hätte Folgendes das Gleiche getan wie das obige Beispiel: `git log -L '/unsigned long git_deflate_bound/',/^}/:zlib.c`.
160
+
Sie können Git auch einen Bereich von Zeilen oder eine einzelne Zeilennummer geben und Sie erhalten die gleiche Art von Ausgabe.
0 commit comments