Skip to content

Commit 3c0218b

Browse files
committed
General rewording/grammar/font cleanup of "Revision Selection"
As usual: - standardize on " -- " for em dashes - rewording for clarity - add a TIP or two
1 parent a8f1411 commit 3c0218b

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

book/07-git-tools/sections/revision-selection.asc

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[[_revision_selection]]
22
=== Revision Selection
33

4-
Git allows you to specify specific commits or a range of commits in several ways.
4+
Git allows you to refer to a set of commits or a range of commits in several ways.
55
They aren’t necessarily obvious but are helpful to know.
66

77
==== Single Revisions
88

9-
You can obviously refer to a commit by the SHA-1 hash that it’s given, but there are more human-friendly ways to refer to commits as well.
10-
This section outlines the various ways you can refer to a single commit.
9+
You can obviously refer to any single commit by its full, 40-character SHA-1 hash, but there are more human-friendly ways to refer to commits as well.
10+
This section outlines the various ways you can refer to any commit.
1111

1212
==== Short SHA-1
1313

14-
Git is smart enough to figure out what commit you meant to type if you provide the first few characters, as long as your partial SHA-1 is at least four characters long and unambiguousthat is, only one object in the current repository begins with that partial SHA-1.
14+
Git is smart enough to figure out what commit you're referring to if you provide the first few characters of the SHA-1 hash, as long as that partial hash is at least four characters long and unambiguous; that is, no other object in the object database can have a hash that begins with the same prefix.
1515

16-
For example, to see a specific commit, suppose you run a `git log` command and identify the commit where you added certain functionality:
16+
For example, to examine a specific commit where you know you added certain functionality, you might first run `git log` command to locate the commit:
1717

1818
[source,console]
1919
----
@@ -38,7 +38,8 @@ Date: Thu Dec 11 14:58:32 2008 -0800
3838
added some blame and merge stuff
3939
----
4040

41-
In this case, choose `1c002dd...`. If you `git show` that commit, the following commands are equivalent (assuming the shorter versions are unambiguous):
41+
In this case, say you're interested in the commit whose hash begins with `1c002dd...`.
42+
You can inspect that commit with any of the following variations of `git show` (assuming the shorter versions are unambiguous):
4243

4344
[source,console]
4445
----
@@ -59,17 +60,16 @@ a11bef0 first commit
5960
----
6061

6162
Generally, eight to ten characters are more than enough to be unique within a project.
62-
63-
As an example, the Linux kernel, which is a pretty large project with over 450k commits and 3.6 million objects, has no two objects whose SHA-1s overlap more than the first 11 characters.
63+
For example, as of October 2017, the Linux kernel (which is a fairly sizable project) has over 700,000 commits and almost six million objects, with no two objects whose SHA-1s are identical in the first 11 characters.
6464

6565
[NOTE]
6666
.A SHORT NOTE ABOUT SHA-1
6767
====
6868
69-
A lot of people become concerned at some point that they will, by random happenstance, have two objects in their repository that hash to the same SHA-1 value.
69+
A lot of people become concerned at some point that they will, by random happenstance, have two distinct objects in their repository that hash to the same SHA-1 value.
7070
What then?
7171
72-
If you do happen to commit an object that hashes to the same SHA-1 value as a previous object in your repository, Git will see the previous object already in your Git database and assume it was already written.
72+
If you do happen to commit an object that hashes to the same SHA-1 value as a previous _different_ object in your repository, Git will see the previous object already in your Git database, assume it was already written and simply reuse it.
7373
If you try to check out that object again at some point, you’ll always get the data of the first object.
7474
7575
However, you should be aware of how ridiculously unlikely this scenario is.
@@ -89,9 +89,8 @@ Thus, a SHA-1 collision is less likely than every member of your programming tea
8989
[[_branch_references]]
9090
==== Branch References
9191

92-
The most straightforward way to specify a commit requires that it has a branch reference pointed at it.
93-
Then, you can use a branch name in any Git command that expects a commit object or SHA-1 value.
94-
For instance, if you want to show the last commit object on a branch, the following commands are equivalent, assuming that the `topic1` branch points to `ca82a6d`:
92+
One straightforward way to refer to a particular commit is if it's the commit at the tip of a branch; in that case, you can simply use the branch name in any Git command that expects a reference to a commit.
93+
For instance, if you want to examine the last commit object on a branch, the following commands are equivalent, assuming that the `topic1` branch points to commit `ca82a6d...`:
9594

9695
[source,console]
9796
----
@@ -113,7 +112,7 @@ ca82a6dff817ec66f44342007202690a93763949
113112
[[_git_reflog]]
114113
==== RefLog Shortnames
115114

116-
One of the things Git does in the background while you’re working away is keep a ``reflog'' a log of where your HEAD and branch references have been for the last few months.
115+
One of the things Git does in the background while you’re working away is keep a ``reflog'' -- a log of where your HEAD and branch references have been for the last few months.
117116

118117
You can see your reflog by using `git reflog`:
119118

@@ -130,8 +129,8 @@ d921970 HEAD@{1}: merge phedders/rdocs: Merge made by the 'recursive' stategy.
130129
----
131130

132131
Every time your branch tip is updated for any reason, Git stores that information for you in this temporary history.
133-
And you can specify older commits with this data, as well.
134-
If you want to see the fifth prior value of the HEAD of your repository, you can use the `@{5}` reference that you see in the reflog output:
132+
You can use your reflog data to refer to older commits as well.
133+
For example, if you want to see the fifth prior value of the HEAD of your repository, you can use the `@{5}` reference that you see in the reflog output:
135134

136135
[source,console]
137136
----
@@ -146,7 +145,7 @@ For instance, to see where your `master` branch was yesterday, you can type
146145
$ git show master@{yesterday}
147146
----
148147

149-
That shows you where the branch tip was yesterday.
148+
That would show you where tip of your `master` branch was yesterday.
150149
This technique only works for data that’s still in your reflog, so you can’t use it to look for commits older than a few months.
151150

152151
To see reflog information formatted like the `git log` output, you can run `git log -g`:
@@ -171,9 +170,15 @@ Date: Thu Dec 11 15:08:43 2008 -0800
171170
Merge commit 'phedders/rdocs'
172171
----
173172

174-
It’s important to note that the reflog information is strictly local – it’s a log of what you’ve done in your repository.
175-
The references won’t be the same on someone else’s copy of the repository; and right after you initially clone a repository, you'll have an empty reflog, as no activity has occurred yet in your repository.
176-
Running `git show HEAD@{2.months.ago}` will work only if you cloned the project at least two months ago – if you cloned it five minutes ago, you’ll get no results.
173+
It’s important to note that reflog information is strictly local -- it’s a log only of what _you've_ done in _your_ repository.
174+
The references won’t be the same on someone else’s copy of the repository; also, right after you initially clone a repository, you'll have an empty reflog, as no activity has occurred yet in your repository.
175+
Running `git show HEAD@{2.months.ago}` will show you the matching commit only if you cloned the project at least two months ago -- if you cloned it any more recently than that, you'll see only your first local commit.
176+
177+
[TIP]
178+
.Think of the reflog as Git's version of shell history
179+
====
180+
If you have a UNIX or Linux background, you can think of the reflog as Git's version of shell history, which emphasizes that what's there is clearly relevant only for you and your ``session'', and has nothing to do with anyone else who might be working on the same machine.
181+
====
177182

178183
==== Ancestry References
179184

@@ -223,7 +228,7 @@ $ git show "HEAD^" # OK
223228
====
224229

225230
You can also specify a number after the `^` – for example, `d921970^2` means ``the second parent of d921970.''
226-
This syntax is only useful for merge commits, which have more than one parent.
231+
This syntax is useful only for merge commits, which have more than one parent.
227232
The first parent is the branch you were on when you merged, and the second is the commit on the branch that you merged in:
228233

229234
[source,console]
@@ -246,7 +251,7 @@ Date: Wed Dec 10 22:22:03 2008 +0000
246251
The other main ancestry specification is the `~` (tilde).
247252
This also refers to the first parent, so `HEAD~` and `HEAD^` are equivalent.
248253
The difference becomes apparent when you specify a number.
249-
`HEAD~2` means ``the first parent of the first parent,'' or ``the grandparent'' it traverses the first parents the number of times you specify.
254+
`HEAD~2` means ``the first parent of the first parent,'' or ``the grandparent'' -- it traverses the first parents the number of times you specify.
250255
For example, in the history listed earlier, `HEAD~3` would be
251256

252257
[source,console]
@@ -271,13 +276,13 @@ Date: Fri Nov 7 13:47:59 2008 -0500
271276
ignore *.gem
272277
----
273278

274-
You can also combine these syntaxes you can get the second parent of the previous reference (assuming it was a merge commit) by using `HEAD~3^2`, and so on.
279+
You can also combine these syntaxes -- you can get the second parent of the previous reference (assuming it was a merge commit) by using `HEAD~3^2`, and so on.
275280

276281
[[_commit_ranges]]
277282
==== Commit Ranges
278283

279284
Now that you can specify individual commits, let’s see how to specify ranges of commits.
280-
This is particularly useful for managing your branches if you have a lot of branches, you can use range specifications to answer questions such as, ``What work is on this branch that I haven’t yet merged into my main branch?''
285+
This is particularly useful for managing your branches -- if you have a lot of branches, you can use range specifications to answer questions such as, ``What work is on this branch that I haven’t yet merged into my main branch?''
281286

282287
===== Double Dot
283288

@@ -289,8 +294,8 @@ For example, say you have a commit history that looks like <<double_dot>>.
289294
.Example history for range selection.
290295
image::images/double-dot.png[Example history for range selection.]
291296

292-
You want to see what is in your experiment branch that hasn’t yet been merged into your master branch.
293-
You can ask Git to show you a log of just those commits with `master..experiment` that means ``all commits reachable by experiment that aren’t reachable by master.''
297+
Say you want to see what is in your `experiment` branch that hasn’t yet been merged into your `master` branch.
298+
You can ask Git to show you a log of just those commits with `master..experiment` -- that means ``all commits reachable from experiment that aren’t reachable from master.''
294299
For the sake of brevity and clarity in these examples, the letters of the commit objects from the diagram are used in place of the actual log output in the order that they would display:
295300

296301
[source,console]
@@ -300,7 +305,7 @@ D
300305
C
301306
----
302307

303-
If, on the other hand, you want to see the opposite all commits in `master` that aren’t in `experiment` you can reverse the branch names.
308+
If, on the other hand, you want to see the opposite -- all commits in `master` that aren’t in `experiment` -- you can reverse the branch names.
304309
`experiment..master` shows you everything in `master` not reachable from `experiment`:
305310

306311
[source,console]
@@ -310,8 +315,8 @@ F
310315
E
311316
----
312317

313-
This is useful if you want to keep the `experiment` branch up to date and preview what you’re about to merge in.
314-
Another very frequent use of this syntax is to see what you’re about to push to a remote:
318+
This is useful if you want to keep the `experiment` branch up to date and preview what you’re about to merge.
319+
Another frequent use of this syntax is to see what you’re about to push to a remote:
315320

316321
[source,console]
317322
----
@@ -320,14 +325,14 @@ $ git log origin/master..HEAD
320325

321326
This command shows you any commits in your current branch that aren’t in the `master` branch on your `origin` remote.
322327
If you run a `git push` and your current branch is tracking `origin/master`, the commits listed by `git log origin/master..HEAD` are the commits that will be transferred to the server.
323-
You can also leave off one side of the syntax to have Git assume HEAD.
324-
For example, you can get the same results as in the previous example by typing `git log origin/master..` Git substitutes HEAD if one side is missing.
328+
You can also leave off one side of the syntax to have Git assume `HEAD`.
329+
For example, you can get the same results as in the previous example by typing `git log origin/master..` -- Git substitutes `HEAD` if one side is missing.
325330

326331
===== Multiple Points
327332

328-
The double-dot syntax is useful as a shorthand; but perhaps you want to specify more than two branches to indicate your revision, such as seeing what commits are in any of several branches that aren’t in the branch you’re currently on.
333+
The double-dot syntax is useful as a shorthand, but perhaps you want to specify more than two branches to indicate your revision, such as seeing what commits are in any of several branches that aren’t in the branch you’re currently on.
329334
Git allows you to do this by using either the `^` character or `--not` before any reference from which you don’t want to see reachable commits.
330-
Thus these three commands are equivalent:
335+
Thus, the following three commands are equivalent:
331336

332337
[source,console]
333338
----
@@ -337,7 +342,7 @@ $ git log refB --not refA
337342
----
338343

339344
This is nice because with this syntax you can specify more than two references in your query, which you cannot do with the double-dot syntax.
340-
For instance, if you want to see all commits that are reachable from `refA` or `refB` but not from `refC`, you can type one of these:
345+
For instance, if you want to see all commits that are reachable from `refA` or `refB` but not from `refC`, you can use either of:
341346

342347
[source,console]
343348
----
@@ -350,9 +355,9 @@ This makes for a very powerful revision query system that should help you figure
350355
[[_triple_dot]]
351356
===== Triple Dot
352357

353-
The last major range-selection syntax is the triple-dot syntax, which specifies all the commits that are reachable by either of two references but not by both of them.
358+
The last major range-selection syntax is the triple-dot syntax, which specifies all the commits that are reachable by _either_ of two references but not by both of them.
354359
Look back at the example commit history in <<double_dot>>.
355-
If you want to see what is in `master` or `experiment` but not any common references, you can run
360+
If you want to see what is in `master` or `experiment` but not any common references, you can run:
356361

357362
[source,console]
358363
----
@@ -366,7 +371,7 @@ C
366371
Again, this gives you normal `log` output but shows you only the commit information for those four commits, appearing in the traditional commit date ordering.
367372

368373
A common switch to use with the `log` command in this case is `--left-right`, which shows you which side of the range each commit is in.
369-
This helps make the data more useful:
374+
This helps make the output more useful:
370375

371376
[source,console]
372377
----

0 commit comments

Comments
 (0)