Git Push 从另一个存储库提交,没有原始用户信息

标签 git git-push git-pull git-remote

我正在客户存储库上开发一个项目,现在我想在客户不知情的情况下添加另一个开发人员。

我尝试设置新的存储库,将其添加为我的计算机中的远程存储库,然后从替代方案(其他开发人员提交的地方)中 pull 并推送到原点(客户端存储库),但即使其他开发人员没有任何访问客户存储库,那里的提交显示为他的。

我应该如何避免这种情况并将他的提交推送到客户存储库作为我的?

e.g.

Developer makes changes to file1 and commits it to repo2

I pull from the repo2 inspect the code & push it to repo1

In repo2 it shows that the file1 is changed & commit is made by Developer

I need that it would show that file1 is changed & commit is made by me under repo 1

最佳答案

Git 允许您指定作者:

git commit ... [--author=<author>]

让开发者使用您的名字,您的要求就会得到满足。

示例:

$ git init
Initialized empty Git repository in c:/projects/bb/.git/

$ touch a
$ git add a
$ git commit -m "new file" --author="Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01646c60686d41606565736472722f626e6c" rel="noreferrer noopener nofollow">[email protected]</a>>"
[master (root-commit) cb6ca75] new file
 Author: Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01646c60686d41606565736472722f626e6c" rel="noreferrer noopener nofollow">[email protected]</a>>
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a

$ git log
commit cb6ca75753e13de07202f131d730c68df1a96941
Author: Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8bdb5b9b1b498b9bcbcaabdababf6bbb7b5" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Thu Aug 13 12:24:21 2015 +0300

    new file

为了确保开发者将代表 Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0c5cdc1c9cce0c1c4c4d2c5d3d38ec3cfcd" rel="noreferrer noopener nofollow">[email protected]</a>> 提交更改您可以添加别名:

git config --local alias.com 'commit --author="Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c0c8c4ccc9e5c4c1c1d7c0d6d68bc6cac8" rel="noreferrer noopener nofollow">[email protected]</a>>"'

然后使用它

$ touch file2
$ git add file2
$ git com -m "File2"
[master ed88a10] File2
 Author: Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8de8e0ece4e1cdece9e9ffe8fefea3eee2e0" rel="noreferrer noopener nofollow">[email protected]</a>>
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file2

$ git log
commit ed88a10d1e1fef95cebd7d9cbc028314e6a3fa54
Author: Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c6a3aba7afaa86a7a2a2b4a3b5b5e8a5a9ab" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Thu Aug 13 12:46:48 2015 +0300

    File2
commit cb6ca75753e13de07202f131d730c68df1a96941
Author: Author Name <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e5b535f57527e5f5a5a4c5b4d4d105d5153" rel="noreferrer noopener nofollow">[email protected]</a>>
Date:   Thu Aug 13 12:24:21 2015 +0300

    new file

关于Git Push 从另一个存储库提交,没有原始用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31983760/

相关文章:

git - 我如何归档旧的 git 标签?

git - 如何在 git commit 失败后重用挂起的评论?

linux - GitHub 使用 ssh 提交不显示在日历上,但文件得到更新

Git rebase 显示非快进

git - `receive.denyCurrentBranch=updateInstead` 如何与索引交互?

git - 如何将 Git 配置为在分支更改时自动从原点 pull ?

git - 当 git fetch 命令中断时,获取的文件会发生什么情况

git - 如何解决与 git 命令行的冲突以保持目标(Visual Studio 2019)?

Git rebase master 和多个分支

git - Git Pull 和 Git Push 之间的死锁