英文:
How to specify commit author on the fly?
问题
你想要只为这个提交签名,可以使用以下命令:
git commit -m "Message" --author="My Name <my_email@email.com>" --signoff
这将允许你仅为此提交签名,而不设置全局默认身份。
英文:
I want to do a commit in a repo. I don't want to set me as the default person signing, i.e. want to avoid git config --global user.email "you@example.com"
and git config --global user.name "Your Name"
. So I am doing git commit -m "Message" --author="My Name <my_email@email.com>"
, but Git says
Committer identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
How can I sign only this commit?
答案1
得分: 3
尝试在提交前设置GIT_AUTHOR_NAME和GIT_AUTHOR_EMAIL环境变量。有关此内容的解释。
#!/bin/bash
GIT_AUTHOR_NAME="Your Name" GIT_AUTHOR_EMAIL=you@example.com git commit -m "Message"
英文:
Try to set GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables before your commit. See the explanation about this.
#!/bin/bash
GIT_AUTHOR_NAME="Your Name" GIT_AUTHOR_EMAIL=you@example.com git commit -m "Message"
答案2
得分: 0
根据我所知,我认为你无法避免编辑你的配置。但是,你可以移除 --global
标志,这样它会保存名称/电子邮件到本地仓库,而不会覆盖你的全局设置。
所以你可以设置本地配置,签署提交,然后取消配置:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git commit -m "Message"
git config --unset user.email
git config --unset user.name
我承认这有点繁琐,特别是如果你经常以这种方式提交。
你还可以使用 git config --edit
编辑本地配置文件,在那里你可以随时注释掉你的名称/电子邮件,以便 "签出"。
英文:
As far as I know, I don't think you can avoid editing your configuration. However, you can remove the --global
flag and it will save the name/email for the local repository instead of overwriting your global settings.
So you could set the local configuration, sign the commit, then unset the configuration:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git commit -m "Message"
git config --unset user.email
git config --unset user.name
Which I admit is a bit tedious, especially if you are committing this way frequently.
You can also edit this local configuration file with git config --edit
, where you can comment out your name/email whenever you want to "sign out".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论