我怎样才能重定义另一个作者提交的提交,而不必将自己添加为提交者? [英] How can I rebase a commit made by another author without adding myself as the committer?

查看:102
本文介绍了我怎样才能重定义另一个作者提交的提交,而不必将自己添加为提交者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当你使用git重定义另一个作者的提交时,git会在你的姓名和电子邮件地址中添加一个 Commit:标头。我有一种情况,我不希望发生这种情况。我希望重新提交的提交以与原作者完成相同的rebase自己的操作相同的SHA1结束。这是可能的吗?

解决方案

所有git提交内部都有一个提交者字段;你可以通过在提交之后立即输入 git cat-file commit HEAD 来看到这一点。因此你不能抹去它;你只能使它等于作者字段。



也就是说,你可能会看到显示提交字段的git瓷器,因为 datestamp 有改变。至少可以预测别人会得到什么样的提交日期戳,如果他们正在重新绑定的话,那么至少可以将其更改为等于原始提交时间戳。

  git filter-branch --commit-filter'export GIT_COMMITTER_NAME =$ GIT_AUTHOR_NAME;导出GIT_COMMITTER_EMAIL =$ GIT_AUTHOR_EMAIL;导出GIT_COMMITTER_DATE =$ GIT_AUTHOR_DATE; git commit-tree$ @' -  basecommit..HEAD 

这会在basecommit之后改变提交,在HEAD(包括HEAD,不包括basecommit)的历史中,使他们的提交者字段在所有方面与作者字段相同。如果原作者同意做同样的事情,那么您可以获得一致的SHA1。


Normally, when you rebase another author's commit with git, git adds a Commit: header with your name and email address. I have a situation where I don't want this to happen. I want the rebased commit to end up with the same SHA1 as it would have if the original author had done the equivalent rebase him/herself. Is this possible?

解决方案

All git commits have a committer field internally; you can see this by typing git cat-file commit HEAD immediately after committing something. As such you cannot erase it; you can only make it equal to the author field.

That said, you might be seeing git porcelain showing the commit field because the datestamp has changed. It's not possible to predict what someone else would get for the commit datestamp if they were rebasing, obviously, but you can alter it to be equal to the original commit timestamp, at least.

git filter-branch --commit-filter 'export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; git commit-tree "$@"' -- basecommit..HEAD

This will alter commits after basecommit, in the history of HEAD (including HEAD, not including basecommit), making their committer field identical to the author field in all respects. If the original author agrees to do the same thing, then you can get a consistent SHA1.

这篇关于我怎样才能重定义另一个作者提交的提交,而不必将自己添加为提交者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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