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/replace.asc
+44-44Lines changed: 44 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
[[_replace]]
2
-
=== Replace
2
+
=== Replace (Ersetzen)
3
3
4
-
As we've emphasized before, the objects in Git's object database are unchangeable, but Git does provide an interesting way to _pretend_ to replace objects in its database with other objects.
4
+
Wie wir bereits betont haben, sind die Objekte in der Objektdatenbank von Git unveränderbar, aber Git bietet eine interessante Möglichkeit, so _zu tun, als ob_ man Objekte in der Datenbank durch andere Objekte ersetzen würde.
5
5
6
-
The `replace` command lets you specify an object in Git and say "every time you refer to _this_ object, pretend it's a _different_ object".
7
-
This is most commonly useful for replacing one commit in your history with another one without having to rebuild the entire history with, say, `git filter-branch`.
6
+
Der Befehl `replace` ermöglicht es Ihnen, ein Objekt in Git zu bestimmen und zu sagen „jedes Mal, wenn ich auf _dieses_ Objekt verweise, behandle es so, als wäre es ein _anderes_ Objekt“.
7
+
Das wird am häufigsten gebraucht zum Ersetzen eines Commits in Ihrem Verlauf durch einen anderen, ohne dass Sie die gesamte Historie neu aufbauen müssen, wie z.B. mit `git filter-branch`.
8
8
9
-
For example, let's say you have a huge code history and want to split your repository into one short history for new developers and one much longer and larger history for people interested in data mining.
10
-
You can graft one history onto the other by "replacing" the earliest commit in the new line with the latest commit on the older one.
11
-
This is nice because it means that you don't actually have to rewrite every commit in the new history, as you would normally have to do to join them together (because the parentage affects the SHA-1s).
9
+
Nehmen wir zum Beispiel an, Sie haben einen riesigen Code-Verlauf und möchten Ihr Repository aufsplitten in einen kurzen Verlauf für neue Entwickler und einen viel längeren und ausführlicheren Verlauf für Leute, die sich für Data Mining interessieren.
10
+
Sie können eine Historie auf eine andere aufpfropfen, indem Sie den frühesten Commit in der neuen Zeile durch den neuesten Commit in der älteren Zeile „ersetzen“.
11
+
Das ist angenehm, weil es bedeutet, dass Sie nicht wirklich jeden Commit in der neuen Geschichte neu erstellen müssen, wie Sie es normalerweise tun müssten, um sie zusammenzufügen (weil die Elterngeneration die SHA-1s beeinflussen).
12
12
13
-
Let's try this out.
14
-
Let's take an existing repository, split it into two repositories, one recent and one historical, and then we'll see how we can recombine them without modifying the recent repositories SHA-1 values via `replace`.
13
+
Probieren wir das einmal aus.
14
+
Nehmen wir ein vorhandenes Repository, teilen es in zwei Repositories auf, ein aktuelles und ein altes, und dann sehen wir, wie wir sie rekombinieren können, ohne die aktuellen SHA-1-Werte des Repositories durch `replace` zu verändern.
15
15
16
-
We'll use a simple repository with five simple commits:
16
+
Wir werden ein kleines Repository mit fünf einfachen Commits verwenden:
17
17
18
18
[source,console]
19
19
----
@@ -25,13 +25,13 @@ c6e1e95 Fourth commit
25
25
c1822cf First commit
26
26
----
27
27
28
-
We want to break this up into two lines of history.
29
-
One line goes from commit one to commit four - that will be the historical one.
30
-
The second line will just be commits four and five - that will be the recent history.
28
+
Wir wollen dieses in zwei unterschiedliche Historien aufteilen.
29
+
Eine Linie geht von „commit one“ bis „commit four“ – das wird die historische Linie sein.
30
+
Die zweite Linie wird nur aus den Commits vier und fünf bestehen – das wird die jüngere Historie sein.
31
31
32
32
image::images/replace1.png[]
33
33
34
-
Well, creating the historical history is easy, we can just put a branch in the history and then push that branch to the `master` branch of a new remote repository.
34
+
Nun, die Erstellung des historischen Verlaufs ist einfach, wir können einen Branch in den Verlauf einfügen und dann diesen Branch auf den `master` Branch eines neuen Remote-Repositorys pushen.
35
35
36
36
[source,console]
37
37
----
@@ -46,7 +46,7 @@ c1822cf First commit
46
46
47
47
image::images/replace2.png[]
48
48
49
-
Now we can push the new `history` branch to the `master` branch of our new repository:
49
+
Jetzt können wir den neuen Branch `history` in den `master` Branch unseres neuen Repositorys pushen:
Now the harder part is truncating our recent history down so it's smaller.
67
-
We need an overlap so we can replace a commit in one with an equivalent commit in the other, so we're going to truncate this to just commits four and five (so commit four overlaps).
65
+
OK, damit ist unsere Historie veröffentlicht.
66
+
Nun ist der schwierigere Teil, unsere jüngste Historie nach hinten zu kürzen, damit sie kleiner wird.
67
+
Wir brauchen eine Überlappung, damit wir einen Commit in der einen durch einen gleichwertigen Commit in der anderen ersetzen können. Deshalb werden wir diesen Teil auf die Commits vier und fünf kürzen (so dass sich Commit vier überlappt).
It's useful in this case to create a base commit that has instructions on how to expand the history, so other developers know what to do if they hit the first commit in the truncated history and need more.
80
-
So, what we're going to do is create an initial commit object as our base point with instructions, then rebase the remaining commits (four and five) on top of it.
79
+
In diesem Fall ist es nützlich, einen Basis-Commit zu erstellen, der Anweisungen zum Erweitern der Historie enthält, damit andere Entwickler wissen, was zu tun ist, wenn sie auf den ersten Commit in der getrennten Historie treffen und mehr brauchen.
80
+
Was wir also vornehmen werden, ist, ein erstes Commit-Objekt als unseren Basispunkt mit Anweisungen zu erstellen und dann die restlichen Commits (vier und fünf) darauf zu rebasieren.
81
81
82
-
To do that, we need to choose a point to split at, which for us is the third commit, which is `9c68fdc` in SHA-speak.
83
-
So, our base commit will be based off of that tree.
84
-
We can create our base commit using the `commit-tree` command, which just takes a tree and will give us a brand new, parentless commit object SHA-1 back.
82
+
Dazu müssen wir einen Punkt wählen, an dem wir abspalten möchten, der in unserem Beispiel der dritte Commit ist. Er lautet `9c68fdc` in der SHA-Sprechweise.
83
+
Unser Basis-Commit wird also auf diesem Baum basieren.
84
+
Wir können unseren Basis-Commit mit dem Befehl `commit-tree` erstellen, der einfach einen Baum nimmt und uns ein brandneues, elternloses SHA-1 Commit-Objekt zurückgibt.
85
85
86
86
[source,console]
87
87
----
@@ -91,16 +91,16 @@ $ echo 'Get history from blah blah blah' | git commit-tree 9c68fdc^{tree}
91
91
92
92
[NOTE]
93
93
=====
94
-
The `commit-tree` command is one of a set of commands that are commonly referred to as 'plumbing' commands.
95
-
These are commands that are not generally meant to be used directly, but instead are used by *other* Git commands to do smaller jobs.
96
-
On occasions when we're doing weirder things like this, they allow us to do really low-level things but are not meant for daily use.
97
-
You can read more about plumbing commands in <<ch10-git-internals#_plumbing_porcelain>>
94
+
Das Kommando `commit-tree` gehört zu einer Reihe von Befehlen, die allgemein als „Basis“-Befehle (engl. 'plumbing' commands) bezeichnet werden.
95
+
Diese Befehle sind im Allgemeinen nicht für den direkten Einsatz gedacht, sondern werden, eingebettet in *andere* Git-Befehle, für kleinere Aufgaben verwendet.
96
+
Wenn wir bei derartigen Gelegenheiten etwas Ungewöhnliches durchführen müssen, dann erlauben sie uns, echte low-level Aufgaben zu erledigen, sind aber nicht für den täglichen Gebrauch gedacht.
97
+
Sie können mehr über Basisbefehle in <<ch10-git-internals#_plumbing_porcelain>> lesen.
98
98
=====
99
99
100
100
image::images/replace3.png[]
101
101
102
-
OK, so now that we have a base commit, we can rebase the rest of our history on top of that with `git rebase --onto`.
103
-
The `--onto` argument will be the SHA-1 we just got back from `commit-tree` and the rebase point will be the third commit (the parent of the first commit we want to keep, `9c68fdc`):
102
+
OK, jetzt, wo wir einen Basis-Commit haben, können wir den Rest unseres Verlaufs mit `git rebase --onto` auf die Basis zurückführen.
103
+
Das Argument `--onto` wird der SHA-1 sein, den wir gerade von `commit-tree` zurückbekommen haben und der Rebase-Punkt wird der dritte Commit sein (der Elternteil des ersten Commits, den wir behalten wollen, `9c68fdc`):
104
104
105
105
[source,console]
106
106
----
@@ -112,11 +112,11 @@ Applying: fifth commit
112
112
113
113
image::images/replace4.png[]
114
114
115
-
OK, so now we've re-written our recent history on top of a throw away base commit that now has instructions in it on how to reconstitute the entire history if we wanted to.
116
-
We can push that new history to a new project and now when people clone that repository, they will only see the most recent two commits and then a base commit with instructions.
115
+
Gut, nun haben wir also unseren jüngsten Verlauf auf einer Übergabebasis neu geschrieben, die jetzt Anweisungen enthält, wie wir die gesamte Historie rekonstruieren könnten, wenn wir es wollen.
116
+
Wir können diesen neuen Verlauf auf ein neues Projekt übertragen und wenn die Anwender jetzt dieses Repository klonen, sehen sie nur die beiden letzten Commits und dann einen Basis-Commit mit Instruktionen.
117
117
118
-
Let's now switch roles to someone cloning the project for the first time who wants the entire history.
119
-
To get the history data after cloning this truncated repository, one would have to add a second remote for the historical repository and fetch:
118
+
Lassen Sie uns nun die Rolle tauschen zu jemand, der das Projekt zum ersten Mal klont und den gesamten Verlauf des Projekts haben will.
119
+
Um die Verlaufsdaten nach dem Klonen dieses abgetrennten Repositorys zu erhalten, müsste man einen zweiten Remote für das historische Repository hinzufügen und fetchen:
120
120
121
121
[source,console]
122
122
----
@@ -134,7 +134,7 @@ From https://github.com/schacon/project-history
134
134
* [new branch] master -> project-history/master
135
135
----
136
136
137
-
Now the collaborator would have their recent commits in the `master` branch and the historical commits in the `project-history/master` branch.
137
+
Nun würde der Mitarbeitende seine jüngsten Commits im `master` Branch und die historischen Commits im `project-history/master` Branch erhalten.
138
138
139
139
[source,console]
140
140
----
@@ -150,15 +150,15 @@ c6e1e95 Fourth commit
150
150
c1822cf First commit
151
151
----
152
152
153
-
To combine them, you can simply call `git replace` with the commit you want to replace and then the commit you want to replace it with.
154
-
So we want to replace the "fourth" commit in the `master` branch with the "fourth" commit in the `project-history/master` branch:
153
+
Um sie zu vereinigen, können Sie einfach `git replace` mit dem Commit, den Sie ersetzen wollen und dann den Commit, mit dem Sie ihn ersetzen wollen, aufrufen.
154
+
Wir wollen also den „vierten“ Commit im `master` Branch durch den "vierten" Commit im `project-history/master` Branch ersetzen:
155
155
156
156
[source,console]
157
157
----
158
158
$ git replace 81a708d c6e1e95
159
159
----
160
160
161
-
Now, if you look at the history of the `master` branch, it appears to look like this:
161
+
Wenn man sich nun den Verlauf des `master` Branchs anschaut, sieht er so aus:
162
162
163
163
[source,console]
164
164
----
@@ -170,12 +170,12 @@ e146b5f Fifth commit
170
170
c1822cf First commit
171
171
----
172
172
173
-
Cool, right? Without having to change all the SHA-1s upstream, we were able to replace one commit in our history with an entirely different commit and all the normal tools (`bisect`, `blame`, etc) will work how we would expect them to.
173
+
Klasse, oder? Ohne alle SHA-1s im Upstream ändern zu müssen, waren wir in der Lage, einen Commit in unserer Geschichte durch einen ganz anderen zu ersetzen, und alle normalen Werkzeuge (`bisect`, `blame`, usw.) werden so funktionieren, wie wir es erwarten dürfen.
174
174
175
175
image::images/replace5.png[]
176
176
177
-
Interestingly, it still shows `81a708d` as the SHA-1, even though it's actually using the `c6e1e95` commit data that we replaced it with.
178
-
Even if you run a command like `cat-file`, it will show you the replaced data:
177
+
Interessanterweise zeigt das Log immer noch `81a708d` als SHA-1, obwohl es tatsächlich die `c6e1e95` Commit-Daten verwendet, durch die wir es ersetzt haben.
178
+
Selbst wenn Sie einen Befehl wie `cat-file` ausführen, zeigt er Ihnen die ersetzten Daten an:
This means that it's easy to share our replacement with others, because we can push this to our server and other people can easily download it.
206
-
This is not that helpful in the history grafting scenario we've gone over here (since everyone would be downloading both histories anyhow, so why separate them?) but it can be useful in other circumstances.
205
+
Das bedeutet, dass es einfach ist, unseren Ersatz mit anderen zu teilen, weil wir diesen auf unseren Server pushen können und andere Anwender ihn leicht herunterladen können.
206
+
Das ist in dem Szenario zur Verlaufsoptimierung, das wir hier durchgespielt haben, nicht so hilfreich (da jeder sowieso beide Historien herunterladen würde. Warum also beide trennen?). Es kann aber unter anderen Umständen sinnvoll sein.
0 commit comments