简体   繁体   English

GitHub 动作提交归属

[英]GitHub actions commit attribution

Please don't ask why, but I have 2 GitHub accounts.请不要问为什么,但我有 2 个 GitHub 帐户。 I'll call these two accounts GH1 and GH2.我将这两个帐户称为 GH1 和 GH2。

The repository : The repository is private, it is in an organization, and the only members of the organization are GH1 and GH2.存储库:存储库是私有的,它在一个组织中,组织的唯一成员是 GH1 和 GH2。 It is a repository that I don't want linked to my main, GH1, which is why I want there to be no trace of GH1 on that repository, and why I am only pushing to it as GH2.这是一个我不想链接到我的主要 GH1 的存储库,这就是为什么我不希望该存储库上有任何 GH1 的踪迹,以及为什么我只将其作为 GH2 推送到它。

The repository is being used by me to test workflows, before I deploy them to one of the public repositories of the organization.在我将它们部署到组织的公共存储库之一之前,我正在使用该存储库来测试工作流。

When I push to the repo locally (as in, git push ), my commit is attributed to GH2, but when I check the workflow runs, it says that it was pushed by GH1.当我在本地推送到 repo(如git push )时,我的提交归因于 GH2,但是当我检查工作流运行时,它说它是由 GH1 推送的。 How can I make sure that the commit is always attributed to GH2?我如何确保提交始终归因于 GH2?

To clarify : The commit is attributed to GH2, the incorrect attribution to GH1 is in the GitHub Actions workflow runs.澄清一下:提交归因于 GH2,错误归因于 GH1 是在 GitHub 操作工作流运行中。

不正确的 GitHub 操作工作流属性

(It has been modified with inspect element to redact sensitive information.) (已使用 inspect element 对其进行修改以编辑敏感信息。)

There are two past solutions on Stack Overflow for fixing your situation. Stack Overflow 上有两种过去的解决方案可以解决您的问题。

  1. For making future commits use the correct user:为了使将来的提交使用正确的用户:
  1. For changing past commits to swap a user with another:要更改过去的提交以将用户与另一个用户交换:

(Which is part of this question: How to amend several commits in Git to change author ) (这是这个问题的一部分: 如何修改 Git 中的几个提交以更改作者

Part 1:第1部分:

Set your git author settings.设置您的 git 作者设置。 Eg:例如:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Then reset the author for all commits after the given SHA然后在给定的 SHA 之后为所有提交重置作者

git rebase -i YOUR_SHA -x "git commit --amend --reset-author -CHEAD"

This will pop up your editor to confirm the changes.这将弹出您的编辑器以确认更改。 All you need to do here is save and quit and it will go through each commit and run the command specified in the -x flag.您需要在这里做的就是保存并退出,它会通过每次提交 go 并运行 -x 标志中指定的命令。

You can also change the author while maintaining the original timestamps with:您还可以在保持原始时间戳的同时更改作者:

git rebase -i YOUR_SHA -x "git commit --amend --author 'New Name <new_address@example.com>' -CHEAD"

Part 2:第2部分:

git filter-branch --env-filter 'if [ "$GIT_AUTHOR_EMAIL" = "incorrect@email" ]; then
     GIT_AUTHOR_EMAIL=correct@email;
     GIT_AUTHOR_NAME="Correct Name";
     GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL;
     GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; fi' -- --all

I would read the details from the links to make sure you understand what you're doing before executing the actions.我会阅读链接中的详细信息,以确保您在执行操作之前了解自己在做什么。

Git: fatal: Could not read from remote repository. Git:致命:无法从远程存储库读取。 Please make sure you have the correct access rights and the repository exists 请确保您具有正确的访问权限并且存储库存在

Try pushing with SSH instead.尝试用 SSH 代替。 I'd create 2 keys for GH1 and GH2, and then edit my SSH config to something like this:我会为 GH1 和 GH2 创建 2 个密钥,然后将我的 SSH 配置编辑为如下内容:

Host github.com-GH2
        HostName github.com
        User GH2
        IdentityFile ~/.ssh/github_GH2

and in the repositories where I want to be attributed as GH2, I can simply run this git command:在我想归为 GH2 的存储库中,我可以简单地运行这个 git 命令:

git remote set-url origin git@github.com-GH2:user/repo.git

I did a push with that SSH url set, and I'm proud to say that the GitHub Actions workflow runs no longer attributes the commit to GH1 (see below screenshot).我使用 SSH url 集进行了推送,我很自豪地说 GitHub 操作工作流运行不再将提交归因于 GH1(见下文)。

最后,更正 GitHub 归属地

I found a git identity manager.我找到了一个 git 身份管理器。 Hopefully I can use this to change between GH1 and GH2, but I haven't tried it yet for GitHub Actions.希望我可以使用它在 GH1 和 GH2 之间切换,但我还没有尝试过 GitHub 动作。

https://github.com/samrocketman/git-identity-manager https://github.com/samrocketman/git-identity-manager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM