Merge branch 'pb/commit-where'
* pb/commit-where: tutorial: update output of git commit reformat informational commit message git commit: Reformat output somewhat builtin-commit.c: show on which branch a commit was added
This commit is contained in:
@ -32,22 +32,27 @@ Initialized empty Git repository in .git/
|
|||||||
$ echo 'hello world' > file.txt
|
$ echo 'hello world' > file.txt
|
||||||
$ git add .
|
$ git add .
|
||||||
$ git commit -a -m "initial commit"
|
$ git commit -a -m "initial commit"
|
||||||
Created initial commit 54196cc2703dc165cbd373a65a4dcf22d50ae7f7
|
[master (root-commit)] created 54196cc: "initial commit"
|
||||||
|
1 files changed, 1 insertions(+), 0 deletions(-)
|
||||||
create mode 100644 file.txt
|
create mode 100644 file.txt
|
||||||
$ echo 'hello world!' >file.txt
|
$ echo 'hello world!' >file.txt
|
||||||
$ git commit -a -m "add emphasis"
|
$ git commit -a -m "add emphasis"
|
||||||
Created commit c4d59f390b9cfd4318117afde11d601c1085f241
|
[master] created c4d59f3: "add emphasis"
|
||||||
|
1 files changed, 1 insertions(+), 1 deletions(-)
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|
||||||
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.
|
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
|
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
|
contents; among other things, this ensures that git will never store
|
||||||
the same data twice (since identical data is given an identical SHA1
|
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
|
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
|
It is expected that the content of the commit object you created while
|
||||||
following the example above generates a different SHA1 hash than
|
following the example above generates a different SHA1 hash than
|
||||||
|
|||||||
@ -879,6 +879,9 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
|
|||||||
{
|
{
|
||||||
struct rev_info rev;
|
struct rev_info rev;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
|
static const char *format = "format:%h: \"%s\"";
|
||||||
|
unsigned char junk_sha1[20];
|
||||||
|
const char *head = resolve_ref("HEAD", junk_sha1, 0, NULL);
|
||||||
|
|
||||||
commit = lookup_commit(sha1);
|
commit = lookup_commit(sha1);
|
||||||
if (!commit)
|
if (!commit)
|
||||||
@ -896,18 +899,24 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
|
|||||||
|
|
||||||
rev.verbose_header = 1;
|
rev.verbose_header = 1;
|
||||||
rev.show_root_diff = 1;
|
rev.show_root_diff = 1;
|
||||||
get_commit_format("format:%h: %s", &rev);
|
get_commit_format(format, &rev);
|
||||||
rev.always_show_header = 0;
|
rev.always_show_header = 0;
|
||||||
rev.diffopt.detect_rename = 1;
|
rev.diffopt.detect_rename = 1;
|
||||||
rev.diffopt.rename_limit = 100;
|
rev.diffopt.rename_limit = 100;
|
||||||
rev.diffopt.break_opt = 0;
|
rev.diffopt.break_opt = 0;
|
||||||
diff_setup_done(&rev.diffopt);
|
diff_setup_done(&rev.diffopt);
|
||||||
|
|
||||||
printf("Created %scommit ", initial_commit ? "initial " : "");
|
printf("[%s%s]: created ",
|
||||||
|
!prefixcmp(head, "refs/heads/") ?
|
||||||
|
head + 11 :
|
||||||
|
!strcmp(head, "HEAD") ?
|
||||||
|
"detached HEAD" :
|
||||||
|
head,
|
||||||
|
initial_commit ? " (root-commit)" : "");
|
||||||
|
|
||||||
if (!log_tree_commit(&rev, commit)) {
|
if (!log_tree_commit(&rev, commit)) {
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL);
|
format_commit_message(commit, format + 7, &buf, DATE_NORMAL);
|
||||||
printf("%s\n", buf.buf);
|
printf("%s\n", buf.buf);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user