Skip to content

Commit 02aa6e5

Browse files
authored
Merge pull request #1868 from petk/patch-images-3
Add image captions in Replace section
2 parents 638e5de + a4dedb8 commit 02aa6e5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ We want to break this up into two lines of history.
2929
One line goes from commit one to commit four - that will be the historical one.
3030
The second line will just be commits four and five - that will be the recent history.
3131

32-
image::images/replace1.png[]
32+
.Example Git history
33+
image::images/replace1.png[Example Git history]
3334

3435
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.
3536

@@ -44,7 +45,8 @@ c6e1e95 (history) Fourth commit
4445
c1822cf First commit
4546
----
4647

47-
image::images/replace2.png[]
48+
.Creating a new `history` branch
49+
image::images/replace2.png[Creating a new `history` branch]
4850

4951
Now we can push the new `history` branch to the `master` branch of our new repository:
5052

@@ -97,7 +99,8 @@ On occasions when we're doing weirder things like this, they allow us to do real
9799
You can read more about plumbing commands in <<ch10-git-internals#_plumbing_porcelain>>.
98100
=====
99101

100-
image::images/replace3.png[]
102+
.Creating a base commit using `commit-tree`
103+
image::images/replace3.png[Creating a base commit using `commit-tree`]
101104

102105
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`.
103106
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`):
@@ -110,7 +113,8 @@ Applying: fourth commit
110113
Applying: fifth commit
111114
----
112115

113-
image::images/replace4.png[]
116+
.Rebasing the history on top of the base commit
117+
image::images/replace4.png[Rebasing the history on top of the base commit]
114118

115119
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.
116120
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.
@@ -172,7 +176,8 @@ c1822cf First commit
172176

173177
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.
174178

175-
image::images/replace5.png[]
179+
.Combining the commits with `git replace`
180+
image::images/replace5.png[Combining the commits with `git replace`]
176181

177182
Interestingly, it still shows `81a708d` as the SHA-1, even though it's actually using the `c6e1e95` commit data that we replaced it with.
178183
Even if you run a command like `cat-file`, it will show you the replaced data:

0 commit comments

Comments
 (0)