0

git commit -m "edit S1 and add S2"

would assign a new 40 character SHA1 hash for that latest commit in a commit graph.


1) Is SHA1 hash generator creating hash for string "edit S1 and add S2"?

2) If yes, does git author recommend a standard practice on content of this string("edit S1 and add S2")? Because there could be a chance to generate same hash value for using same string, for different commits...

overexchange
  • 15,768
  • 30
  • 152
  • 347
  • Also unclear on "usage of the string"; the idea is that you can use that hash to navigate to an exact and precise point in Git history to review code changes made at that point in time. Using the hash as anything other than Git metadata would only set you up for failure. – Makoto Jan 17 '19 at 19:25
  • @Makoto I mean, what should be the content of the string? Query edited.. – overexchange Jan 17 '19 at 19:26
  • ...Still not clear what you're asking. It's effectively a summary of what the commit is, but that again is largely used to navigate objects in Git. There have been successful Git collision attacks against repositories (Google did one as a PoC against their own and made _a mistake_), but again - not sure what you mean by "content of the string". – Makoto Jan 17 '19 at 19:30
  • @Makoto I mean commit message – overexchange Jan 17 '19 at 19:32
  • Oh, *that*. That's a *completely* different question to how the hash is generated. – Makoto Jan 17 '19 at 19:32

1 Answers1

0

No. A commit's hash isn't a hash of the commit message, it's a hash of the entire commit object, which contains the commit message, the author/committer info, the author/commit dates, a reference to the parent commit(s), and the contents of the repo at the time of the commit. A collision is essentially impossible, and there's no reason to take special care with the commit message. Not a hash-related one, anyway.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • Are you not satisfied with the dupe...? – Makoto Jan 17 '19 at 19:29
  • @Makoto not really, but I don't care much one way or the other. I prefer actually addressing the question. – hobbs Jan 17 '19 at 19:35
  • Referring the asker to an existing answer _is_ actually addressing the question. – Yawar Jan 17 '19 at 23:59
  • @Yawar in a low-effort, not-very-satisfactory kind of way. It doesn't answer the actual question, it just leaves a pointer to something vaguely similar with no explanation of the connection. – hobbs Jan 18 '19 at 01:43
  • The connection can be explained in a question comment; it doesn't need a full-fledged answer. – Yawar Jan 18 '19 at 01:45