简体   繁体   English

GIT 覆盖代码行的作者(git blame)

[英]GIT Overwrite author of code lines (git blame)

I was trying to find the answer everywhere on the internet but was unsuccessful.我试图在互联网上到处寻找答案,但没有成功。

My problem is that, for some reason, on a new laptop, I put 'email' instead of 'name' and 'password' instead of 'email'.我的问题是,出于某种原因,在一台新笔记本电脑上,我输入了“电子邮件”而不是“名称”和“密码”而不是“电子邮件”。 And now, in history, everyone can see my email and its password (facepalm).而现在,在历史上,每个人都可以看到我的 email 及其密码(facepalm)。

So my question is: is there a way to rename the author's name and email in history?所以我的问题是:历史上有没有办法重命名作者的名字和email?

ps: commit is still in the local branch ps:commit 还在本地分支

screenshot截屏

Simple commit amend fixed the issue.简单的提交修正解决了这个问题。 Sorry for the useless post.对不起,没用的帖子。

git commit --amend --author="Fedor <fedor@bodr.com>" git 提交 --amend --author="Fedor <fedor@bodr.com>"

You literally can't fix the bad commit, but you can stop using it and then be careful not to send it out to any other Git repository so that no one else can see it.您实际上无法修复错误提交,但您可以停止使用它,然后小心不要将其发送到任何其他Git 存储库,以免其他人看到它。

To make a new-and-improved variant of the existing commit, you must copy the original (bad) one to the new-and-improved one.要对现有提交进行新的和改进的变体,您必须将原始(坏)的变体复制到新的和改进的变体。 Copying the last commit on a branch while changing the author information is easy:在更改作者信息的同时复制分支上的最后一次提交很容易:

git commit --amend --reset-author

will use your current user.name and user.email settings.将使用您当前的user.nameuser.email设置。 The existing final commit will be "kicked off the end of the branch", as in this drawing:现有的最终提交将“从分支的末尾开始”,如下图所示:

...--G--H   <-- somebranch (HEAD)

Here H is the "bad" commit and is the most recent;这里H是“错误”提交并且是最近的; this is "before git commit --amend ".这是“在git commit --amend之前”。 This becomes:这变成:

       H
      /
...--G--I   <-- somebranch (HEAD)

Note how commit H is still present in your Git repository, but unless you can find its hash ID , you cannot see commit H any more.请注意,提交H仍然存在于您的 Git 存储库中,但除非您可以找到它的 hash ID ,否则您将无法再看到提交H

If the "bad" commit is further back in the chain:如果“坏”提交在链中更靠后:

...--E--F--G--H   <-- somebranch (HEAD)

where, say, commit F is bad, you have a more difficult task: you must kick commit F off the chain, but this also kicks commits G and H off the chain.比如说,提交F不好,你有一个更困难的任务:你必须将提交F踢出链,但这也会将提交GH踢出链。 This means you must copy F to a new and improved I , and then copy G and H as well.这意味着您必须将F复制到一个新的和改进的I中,然后也复制GH This is harder to do well since git rebase and git cherry-pick want to preserve the original author information, but it's still possible, especially with git rebase -i and git commit --amend . This is harder to do well since git rebase and git cherry-pick want to preserve the original author information, but it's still possible, especially with git rebase -i and git commit --amend .

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

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