Git "git config --global user.name"为什么这个选项存在? [英] Git "git config --global user.name" why does this option exist?

查看:29
本文介绍了Git "git config --global user.name"为什么这个选项存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git 初学者警报!我有一个基本问题,为什么 GIT 允许将用户名更改为配置选项

Git Beginner Alert! I have a basic question as to WHY does GIT allow one to change the user name as a config option

 git config --global user.name trojan

这个选项不会让提交者冒充并在历史/日志中造成混乱吗?为什么不像从用于连接 GIT 的凭据中获取用户名那么简单?

Doesn't this option up the gate for committers to impersonate and create confusion in the history/logs? Why isn't it as simple as take the username from the credentials that are used to connect with GIT?

推荐答案

  1. 正如 Greg 在评论,只能在纯推送工作流程中工作.还有很多其他方法,包括 pure-pull、email、git bundle 或这些的任意组合.
  2. 由于技术原因它不能完全工作:提交的身份是该提交的完整内容的加密校验和,包括提交的作者和<代码>提交者字段.这些必须在创建提交时分配,并且一旦分配,就永远不能更改:要更改"提交的任何部分,请将其复制到新的提交对象,该对象会获得一个新的提交哈希,这只是如果 bit-for-bit 相同,则与原始提交相同.换句话说,我可以通过逐位复制您的提交来冒充您,包括所有源、日志消息、时间戳等.但要做到这一点,我必须 get 你的提交,之后我的副本就是你的提交.在这种情况下,它你的提交,它应该上面有你的名字!
  3. 通常有充分的理由将暴露的身份(用户名和电子邮件)与任何身份验证凭据分开:例如,我用于对 GitHub 进行身份验证的凭据与我用于在其他位置进行身份验证的凭据不同.然而我还是同一个人.可以添加一个间接级别——我使用凭据 A 进行身份验证,然后站点将 A 映射到 B 以获取我的姓名(并在事实上 GitHub 使用 ssh 就是这样做的,因为一个人以 git@github.com 的身份登录")——但这将所有的权力都交给了网站.这与设计理念背道而驰.
  1. As Greg notes in a comment, that can only work in a pure-push workflow. There are many others, including pure-pull, email, git bundle, or any mix of these.
  2. It can't quite work for technical reasons: the identity of a commit is a cryptographic checksum of the complete contents of that commit, including the commit's author and committer fields. These must be assigned at the time the commit is created, and once assigned, can never be changed: to "change" any part of a commit, you copy it to a new commit object, which gets a new commit hash, which is only identical to the original commit if it's bit-for-bit identical. In other words, I can impersonate you by copying your commit bit-for-bit, including all the source, the log message, the time stamps, and so on. But to do that I have to get your commit, after which my copy is just your commit. In which case, it is your commit, and it should have your name on it!
  3. There are often good reasons to separate the exposed identity (user name and email) from any authentication credentials: for instance, the credentials I use to authenticate to GitHub are different from those I use to authenticate to other locations. Yet I am still the same person. One could add a level of indirection—I authenticate using credentials A, and then the site maps A to B to get my name (and in fact GitHub does just that with ssh since one "logs in" as git@github.com)—but that puts all the power in the hands of the site. That's contrary to the design philosophy.

您是否希望确定某个特定提交的真实性 - 例如,您获得一个 ID 为 99154acf3ba... 或类似的提交,并且它声称由 Linus Torvalds 或 Bill Gates 或 Barack Obama 或其他任何人创作——Git 提供了使用某些外部身份验证服务的能力,例如 PGP,它使用数字签名及其所有复杂性(包括 信任链和撤销).容我们说,这个特定领域有一些正在进行的发展,其中一些对 Git 有一定影响.

Should you wish to establish the authenticity of some particular commit—e.g., you obtain a commit whose ID is 99154acf3ba... or some such, and it claims to be authored by Linus Torvalds or Bill Gates or Barack Obama or whatever—Git provides the ability to use some external authentication service, such as PGP, that uses digital signatures and all their complexities (including both Chain of Trust and revocation). This particular field has, shall we say, some ongoing developments, some of which affect Git somewhat.

(通过 GPG 进行的 PGP 身份验证 内置在 Git 中,但由外部程序完成.这里特别明显的弱点是签名标签或提交仅验证一个标签或提交本身.进一步的身份验证取决于关于 Merkle 树 的安全性,该树相当受到损害Git 对 SHA-1 的使用,但越来越受到怀疑:请参阅链接的 StackOverflow 问题.)

(PGP authentication via GPG is built in to Git but done by external programs. The particularly glaring weakness here is that a signed tag or commit verifies only the one tag or commit itself. Further authentication depends on the security of the Merkle tree, which is not quite compromised for Git's usage of SHA-1 yet, but is getting suspect: see linked StackOverflow question.)

这篇关于Git "git config --global user.name"为什么这个选项存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆