git 如何更改bitbucket中提交的用户名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23427247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:00:34  来源:igfitidea点击:

How to change committed User name in bitbucket?

gitgit-svnbitbucketbitbucket-api

提问by Amrit Dhungana

How to change commit username in bitbucket account ? To change in git I have used this command

如何更改 bitbucket 帐户中的提交用户名?为了改变 git 我使用了这个命令

 git filter-branch -f --env-filter " GIT_AUTHOR_NAME='newUser' GIT_AUTHOR_EMAIL='[email protected]' " HEAD

It only change username in local machine but not in my bitbucket account. How to change committed username in bitbucket ?

它只更改本地计算机中的用户名,而不更改我的 bitbucket 帐户中的用户名。如何更改 bitbucket 中提交的用户名?

回答by Alexandru Guzinschi

Like Chrissaid, it is a bad practice to rewrite your git history.

就像Chris所说,重写 git 历史记录是一种不好的做法。

The recommended way to map authors is to use the .mailmapfeature.

映射作者的推荐方法是使用.mailmap功能。

Create a .mailmapfile at the top level of your repository with the following content:

.mailmap使用以下内容在存储库的顶层创建一个文件:

New Name <[email protected]> Old Name <[email protected]>

This will replace Old Name <[email protected]>in git history with New Name <[email protected]>and these changes will also reflect on Github and Bitbucket.

这将Old Name <[email protected]>在 git 历史中替换为,New Name <[email protected]>并且这些更改也将反映在 Github 和 Bitbucket 上。

回答by Chris

Like (almost) everything else with Git, this command only modifies your local repository. Just like when you commit or add a tag, you will have to push to BitBucket in order to make the changes show up.

与 Git 的(几乎)其他所有内容一样,此命令仅修改您的本地存储库。就像提交或添加标签时一样,您必须推送到 BitBucket 才能显示更改。

But before you do, be very surethat you want to.

但在你这样做之前,请确定你想要。

The filter-branchcommand that you ran rewrote your history. Each of your commits now has a new hash. It is considered bad practice to rewrite history that has been shared with others, and if you push to BitBucket you'll be doing that.

filter-branch您运行的命令改写了您的历史记录。您的每个提交现在都有一个新的哈希值。重写与他人共享的历史记录认为是不好的做法,如果你推送到 BitBucket,你就会这样做。

This can cause real problems, most obviously because anybody else who has cloned the repository will now have history that is no longer reflected inthe repository. They will have trouble pushing and fetching (or pulling). If you choose to go forward, it is best to carefully and honestly communicate with all of your collaborators.

这可能会导致真正的问题,最明显的是因为克隆存储库的任何其他人现在都将拥有不再反映存储库的历史记录。他们会遇到麻烦pushing 和fetching(或pulling)。如果您选择继续前进,最好与您的所有合作者仔细、诚实地沟通。

If you are very, very surethat you want to do this, you'll have to use the --force-with-leaseoption to push, or else BitBucket will reject the push.

如果您非常非常确定要执行此操作,则必须使用--force-with-lease推送选项,否则 BitBucket 将拒绝推送。

回答by Nic Wortel

  1. git filter-branchrewrites your history. This can cause problems if you have shared your repository with other people, so be careful!
  2. Make sure you have pushed the result of the filter-branchoperation to the remote repository. Since you have messed with historic commits, you probably need to use git push -ffor this. git push(without -f) will notice you of the fact that your local and remote branches have diverged, this is because of the fact that you have rewritten your history. Again, be careful before you use git push -f!
  3. Sites like Bitbucket and GitHub try to link commits to users instead of simply displaying the commiter's name. This is done by matching the committer's email address to an email address that is associated to one of their users. If you expect Bitbucket to show a link to your user profile, make sure that you have added the new email address to your account. To do so, click on your profile photo in the upper right corner of the site, click 'Manage account', and then in the left sidebar click on 'Email addresses'.
  1. git filter-branch改写你的历史。如果您与其他人共享您的存储库,这可能会导致问题,所以要小心!
  2. 确保您已将filter-branch操作结果推送到远程存储库。由于您弄乱了历史提交,因此您可能需要使用git push -f它。git push(没有-f) 会注意到你的本地和远程分支已经分歧的事实,这是因为你已经重写了你的历史。再次,使用前要小心git push -f
  3. Bitbucket 和 GitHub 等网站尝试将提交链接到用户,而不是简单地显示提交者的姓名。这是通过将提交者的电子邮件地址与与其用户之一相关联的电子邮件地址进行匹配来完成的。如果您希望 Bitbucket 显示指向您的用户个人资料的链接,请确保您已将新电子邮件地址添加到您的帐户。为此,请单击站点右上角的个人资料照片,单击“管理帐户”,然后在左侧边栏中单击“电子邮件地址”。

回答by Ekaba Bisong

Also to change authors in Git for a particular project, one may run:

同样要更改特定项目的 Git 中的作者,可以运行:

git config user.name "Author Name"
git config user.email "[email protected]"

回答by Vinod Joshi

    First of all create two different account into bitbucket
    User: jonny_ceg1
    User: jonny_ceg2

    Now into your computer create two ssh keys;
    $ ssh-keygen -t rsa -C “jonny_ceg1/jonny_ceg2″
    # Creates a new ssh key, using the provided email as a label
    # Generating public/private rsa key pair.
    # Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
    $ ssh-add id_rsa

    Now create a file
    $ ~/.ssh/config

    $ vim ~/.ssh/config # we can use this as editor

    Write following code into that file
    # Default GitHub user (jonny1)
    Host bitbucket.org
    HostName bitbucket.org
    User jonny_ceg1
    IdentityFile /Users/jonny/.ssh/id_rsa

    # Client user (jonny2)
    Host bitbucket.org
    HostName bitbucket.org
    User jonny_ceg12
    IdentityFile /Users/jonny/.ssh/id_rsa2

    by using “IdentityFile”: IdentityFile comment only a single line to avoid jonny_ceg1/jonny_ceg2 as a user


# An Example

## use account 1
# ssh-add ~/.ssh/id_rsa

## use account 2
# ssh-add ~/.ssh/yysshkey

## Check logged in user
# ssh -v [email protected]

# Default GitHub user (jonny)
Host bitbucket.org
  HostName bitbucket.org
  User jonny_oct
 IdentityFile /Users/name/.ssh/id_rsa

# Client user (name)
Host bitbucket.org
  HostName bitbucket.org
  User name_last
#  IdentityFile /Users/name/.ssh/yysshkey

# Original Git hub
Host github.org
  HostName github.org
  User ssUsers
  ForwardAgent yes