How to use the git replace command to update the commit author in Bitbucket Server
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
要約
The steps outlined in this article show how to update the commit author using the git replace command.
環境
Bitbucket Server および Data Center
ソリューション
Follow these steps to change the commit author with the git replace command:
- Clone the repository.
- Locate the commit that requires the author to be changed via the git log command.
Use the commit ID in the git replace command
git replace --edit <commit-id>
- You can now edit the commit. Replace the author with the new details and save your changes.
You'll see a replacement ref created on the local repo under .git/refs/replace. Alternatively, you can run the following command to view the created ref:
git show-ref | grep replace
Push the replacement ref to the remote.
git push origin 'refs/replace/*'
- Locate the repository in Bitbucket and confirm that the author has been changed for the modified commit.
Additional information about replaced objects
Users who have cloned the repository to their local machines may not see the replaced objects. The following command will fetch the replacement refs from the remote repository.
git fetch origin 'refs/replace/*:refs/replace/*'
You can still display the original author when listing the commits on the local repository. This can be done by using the GIT_NO_REPLACE_OBJECTS environment variable.
#Display the original author export GIT_NO_REPLACE_OBJECTS=1 git show <commit-id> #Display the new author unset GIT_NO_REPLACE_OBJECTS git show <commit-id>