我已将一些任务外包给其他用户。将主存储库(工作)的副本复制到另一个远程(私有)。同事已将更改提交到专用遥控器,我想将这些提交与用户一起推送到工作遥控器。 git或某些解决方法中是否有内置方法?
答案 0 :(得分:1)
在本地克隆您的同事仓库,并按以下命令执行:
git filter-branch --env-filter 'export GIT_AUTHOR_NAME="Super Man"; export GIT_AUTHOR_EMAIL="man@superfamily.org"'
(用理想的用户名和邮件代替虚构的字符)
警告:这将重新设置树的基础,并且所有提交ID都会更改
现在您可以按下它了。
另请参见GitHub上的Changing author info
答案 1 :(得分:1)
您可以使用edit进行交互式变基:)
在之前(可能要隐藏此信息;))请验证 author & commiter in git,以免遇到麻烦;)
还请记住,如果您输入有误,可以force push。
2次提交的示例:
* cd6b0ac (HEAD -> master) Fix test file
* e3e822e Add test file
长版(git log
)
commit cd6b0ac5a33283743f524463d0e78a2d3e335e4d (HEAD -> master)
Author: Bob <bob@git.com>
Date: Thu Nov 29 10:26:12 2018 +0000
Fix test file
commit e3e822e89397fdadbd1c6e1ac6710d96590d92c6
Author: Bob <bob@git.com>
Date: Thu Nov 29 10:25:53 2018 +0000
Add test file
现在,我将基于编辑进行基础调整。
git rebase -i e3e822e89397fdadbd1c6e1ac6710d96590d92c6
现在在控制台中,我将看到:
pick cd6b0ac Fix test file
# Rebase e3e822e..cd6b0ac onto e3e822e (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
... (more I don't want paste)
因此,对于此提交,我选择e
并保存->退出。
e cd6b0ac Fix test file
因此,现在您的工作树将检出该提交。 现在,您需要执行2个步骤:
git commit --amend --author="Dawid <dawid@git.com>"
git rebase --continue
转到您选择用来编辑或完成变基的下一个提交。现在git log
进行验证
commit ec0949d075626ed9416d74c02bcbed721b8be2fe (HEAD)
Author: Dawid <dawid@git.com>
Date: Thu Nov 29 10:26:12 2018 +0000
Fix test file
commit e3e822e89397fdadbd1c6e1ac6710d96590d92c6
Author: Bob <bob@git.com>
Date: Thu Nov 29 10:25:53 2018 +0000
Add test file
如果您想选择更多提交来重新确定基准,则可以编写以下内容:git rebase -i HEAD^^
(选择最后2个提交)
要验证,请使用git log --pretty=full
commit ec0949d075626ed9416d74c02bcbed721b8be2fe (HEAD)
Author: Dawid <dawid@git.com>
Commit: Dawid <dawid@git.com>
Fix test file
commit e3e822e89397fdadbd1c6e1ac6710d96590d92c6
Author: Bob <bob@git.com>
Commit: Bob <bob@git.com>
Add test file
了解有关git rebase
的信息