How to change committed User name in bitbucket?

2020-07-22 04:19发布

问题:

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

 git filter-branch -f --env-filter " GIT_AUTHOR_NAME='newUser' GIT_AUTHOR_EMAIL='newuser@email.com' " HEAD

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

回答1:

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.

But before you do, be very sure that you want to.

The filter-branch command 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.

This can cause real problems, most obviously because anybody else who has cloned the repository will now have history that is no longer reflected in the 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.

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



回答2:

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

The recommended way to map authors is to use the .mailmap feature.

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

New Name <new.email@example.com> Old Name <old.email@example.com>

This will replace Old Name <old.email@example.com> in git history with New Name <new.email@example.com> and these changes will also reflect on Github and Bitbucket.



回答3:

  1. git filter-branch rewrites 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-branch operation to the remote repository. Since you have messed with historic commits, you probably need to use git push -f for 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'.


回答4:

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

git config user.name "Author Name"
git config user.email "author@email.com"


回答5:

    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 git@bitbucket.org

# 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