Car*_*arl 104 git command-line commit
我希望能够为脚本执行此操作.我基本上是在Git中重新创建一些代码的整个版本历史 - 它目前使用不同的版本控制系统.我需要脚本能够在保留提交的原始作者(和日期)的同时将提交添加到Git中.
假设我知道提交作者和更改的日期/时间,是否有允许我这样做的Git命令?我假设有,因为git-p4做了类似的事情.我只是要求最好的方法来做到这一点.
fri*_*mle 99
只需添加到这样的:--author在接受的答案中提到的选项只覆盖了作家,而不是提交者的提交信息.
在大多数情况下,这是正确的行为,但如果由于某种原因您需要手动覆盖提交者信息,请使用GIT_COMMITTER_NAME和GIT_COMMITTER_EMAIL环境变量(也有一个GIT_COMMITTER_DATE).请参阅Git-Internals-Environment-Variables
$ GIT_COMMITTER_NAME="New Name" GIT_COMMITTER_EMAIL="name@email.com" git commit --author="New Name <name@email.com>"
Run Code Online (Sandbox Code Playgroud)
这将使提交看起来像是由指定用户创作和提交的.
Bea*_*low 10
使用 -c 选项和 git-commit 来覆盖任何以前的配置。它不会触及您的全局/项目配置。例如,要覆盖姓名和电子邮件:
git -c user.name='My Name' -c user.email='my@email.com' commit -m "Custom message"
Run Code Online (Sandbox Code Playgroud)
但是,如果您打算将其保留为附加设置,我建议您使用别名。编辑您的~/.gitconfig文件并为每个非默认用户和电子邮件附加一个新别名。
[user]
name = My Name
email = default@email.com
[alias]
commit-x = -c user.name='My X Name' -c user.email='mr_x@email.com' commit
commit-y = -c user.name='My Y Name' -c user.email='mr_y@email.com' commit
commit-z = -c user.name='My Z Name' -c user.email='mr_z@email.com' commit
Run Code Online (Sandbox Code Playgroud)
别名将在全球范围内应用。测试一下。
git commit -m "Custom message with committer and author My Name <default@email.com>"
git commit-x -m "Custom message with committer and author My X Name <mr_x@email.com>"
git commit-y -m "Custom message with committer and author My Y Name <mr_y@email.com>"
git commit-z -m "Custom message with committer and author My Z Name <mr_z@email.com>"
Run Code Online (Sandbox Code Playgroud)