Skip to content

Commit 925b297

Browse files
author
Ben Lynn
committed
Added HEAD-hunting section
1 parent eae46ff commit 925b297

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

grandmaster.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Again, only do this if no one else has a clone of your tree.
9191
=== Local Changes Last ===
9292

9393
You're working on an active project. You make some local commits over time, and
94-
then you sync with the official tree with a merge. This cycle repeats itself a few times before you're ready to push to the cetnral tree.
94+
then you sync with the official tree with a merge. This cycle repeats itself a few times before you're ready to push to the central tree.
9595

9696
But now the history in your local Git clone is a messy jumble of your changes and the official changes. You'd prefer to see all your changes in one contiguous section, and after all the official changes.
9797

@@ -117,6 +117,18 @@ But suppose you never took it down? Don't worry, for commands like these, Git sa
117117

118118
$ git reset ORIG_HEAD
119119

120+
=== HEAD-hunting ===
121+
122+
Perhaps ORIG_HEAD isn't enough. Perhaps you've just realized you made a monumental mistake last month and you need to go back to an ancient commit in a long-forgotten branch.
123+
124+
It's hard to lose Git commits permanently, even after deleting branches. As long as you never run git-gc, your commits are preserved forever and can be restored at any time.
125+
126+
The trouble is finding the appropriate hash. You could look at all the hash values in `.git/objects` and use trial and error to find the one you want. But there's a much easier way.
127+
128+
Git records every hash of a commit it computes in `.git/logs`. The subdirectory `refs` contains the history of all activity on all branches, while the file `HEAD` shows every hash value it has ever taken. The latter can be used to find hashes of commits on branches that have been accidentally lopped off.
129+
130+
Eventually, you may want to run git-gc to recover space. Be aware that doing so prevents you from recovering lost HEADs.
131+
120132
=== Building On Git ===
121133

122134
In true UNIX fashion, Git's design allows it to be easily used as a low-level component of other programs. There are GUI interfaces, web interfaces, alternative command-line interfaces, and perhaps soon you will have a script or two of your own that calls Git.

0 commit comments

Comments
 (0)