$ echo 'hello world' > file.txt
$ git add .
$ git commit -a -m "initial commit"
-Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7
+Created root-commit 54196cc (initial commit) on master
create mode 100644 file.txt
$ echo 'hello world!' >file.txt
$ git commit -a -m "add emphasis"
-Created commit c4d59f390b9cfd4318117afde11d601c1085f241
+Created c4d59f3 (add emphasis) on master
------------------------------------------------
-What are the 40 digits of hex that git responded to the commit with?
+What are the 7 digits of hex that git responded to the commit with?
We saw in part one of the tutorial that commits have names like this.
It turns out that every object in the git history is stored under
-such a 40-digit hex name. That name is the SHA1 hash of the object's
+a 40-digit hex name. That name is the SHA1 hash of the object's
contents; among other things, this ensures that git will never store
the same data twice (since identical data is given an identical SHA1
name), and that the contents of a git object will never change (since
-that would change the object's name as well).
+that would change the object's name as well). The 7 char hex strings
+here are simply the abbreviation of such 40 character long strings.
+Abbreviations can be used everywhere where the 40 character strings
+can be used, so long as they are unambiguous.
It is expected that the content of the commit object you created while
following the example above generates a different SHA1 hash than
const char *head = resolve_ref("HEAD", sha, 0, NULL);
struct strbuf buf = STRBUF_INIT;
- strbuf_addstr(&buf, "format:%h");
+ /* use shouty-caps if we're on detached HEAD */
+ strbuf_addf(&buf, "format:%s", strcmp("HEAD", head) ? "" : "DETACHED commit");
+ strbuf_addstr(&buf, "%h (%s)");
- /* Are we on a detached HEAD? */
- if (!strcmp("HEAD", head))
- strbuf_addstr(&buf, " on detached HEAD");
- else if (!prefixcmp(head, "refs/heads/")) {
+ if (!prefixcmp(head, "refs/heads/")) {
const char *cp;
strbuf_addstr(&buf, " on ");
for (cp = head + 11; *cp; cp++) {
strbuf_addch(&buf, *cp);
}
}
- strbuf_addstr(&buf, ": %s");
return strbuf_detach(&buf, NULL);
}
rev.diffopt.break_opt = 0;
diff_setup_done(&rev.diffopt);
- printf("Created %scommit ", initial_commit ? "initial " : "");
+ printf("Created %s", initial_commit ? "root-commit " : "");
if (!log_tree_commit(&rev, commit)) {
struct strbuf buf = STRBUF_INIT;