How do you make changes on a specific commit

Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.

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.

*Except Fisheye and Crucible

Summary

In some unusual cases, a specific commit has to be modified to correct problems when running git fsck on a repository. On the other hand, it may be due to mistakes that were made after committing a change. Before moving on, please be aware of the following items:

  • As this is an unsupported procedure, performing the following is at your risk. Therefore, it is strongly recommended that you create a full backup of your data before performing any of the steps on this page.

  • You may be required to add additional commits on top of the latest commit after making some changes.

  • It is also strongly recommended that you perform this on a local repository or on a test server before performing it in production.

  • Avoid attempting to perform the following if it is not required.

Solution

To perform a change on a specific commit, this KB will use the following output of this git log as an example to demonstrate:

Xyrenus ~/Desktop/repo_sample (master) $ git log commit 3b0065e6a00729f3ee753c162b545f101feb7277 Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:44 2015 +0800 Fourth Commit commit 1f096bfe7503b2805af64b69c9fe12c059ec9000 Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:30 2015 +0800 Third Commit commit 1ffce288fa200abbac4d0789dc181b4e2f2f8cbd Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:20 2015 +0800 Second Commit commit 0ba19e07c5b4e5b2372a51382b910844c81bbefa Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:11 2015 +0800 First Commit

  1. Determine which commit that requires change. In this example, the third commit with the commit hash of 1f096bfe7503b2805af64b69c9fe12c059ec9000 needs to be modified. After that, access the repository via the terminal.

  2. Specify a rebase by identifying an earlier commit to the one that you've chosen above and perform

    git rebase -i <Earlier Commit>

    In this example, the earlier commit would be the second commit with the commit hash of 1ffce288fa200abbac4d0789dc181b4e2f2f8cbd. The command would be:

    git rebase -i 1ffce288fa200abbac4d0789dc181b4e2f2f8cbd

  3. This will open up a text editor; you would need to find the commit that needs changing, and on the same line, replace the word pick to edit for that specific commit. In this example, the text editor will output the following:

    pick 1f096bf Third Commit pick 3b0065e Fourth Commit

    Since we are interested in changing the commit for 1f096bf:

    edit 1f096bf Third Commit pick 3b0065e Fourth Commit

  4. This will allow Git to stop at the Third Commit to make amendments.

  5. Depending on the type of changes, you can perform the following if you need to change:

    • The author of the commit; perform:

      git commit --amend --author="Author Name <email@address.com>"

    • The date of the commit

      1. For the current date and time, perform:

        git commit --amend --date="$(date -R)"

      2. For a specific date and time, perform:

        git commit --amend --date="Thu, 07 Apr 2005 22:13:13 +0200"

        Note that the Date format must follow the Git standard RFC 2822 or ISO 8601 which is described here.

    • The commit message; perform:

      git commit --amend -m "New Commit Message"

  6. After performing any of the above, a text editor will show up again. This allows you to change the commit message if needed. Otherwise, just save it.

  7. Performing git log will show you the changes that you have made on the commit as the latest commit:

    Xyrenus ~/Desktop/repo_sample (master|REBASE-i 1/2) $ git log commit a285de0f648dd807dda329e2d2079ef20cf59118 Author: Andrew Er <andrew@test.com> Date: Sun May 31 12:30:30 2015 +0800 Third Commit - Changed Author commit 1ffce288fa200abbac4d0789dc181b4e2f2f8cbd Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:20 2015 +0800 Second Commit commit 0ba19e07c5b4e5b2372a51382b910844c81bbefa Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:11 2015 +0800 First Commit

    Note that the commit hash for the Third Commit has changed as well

  8. To complete the rebase and to restore back any other existing commits, simply execute git rebase --continue

    Xyrenus ~/Desktop/repo_sample (master|REBASE-i 1/2) $ git rebase --continue Successfully rebased and updated refs/heads/master.
    Xyrenus ~/Desktop/repo_sample (master) $ git log commit 99d6bc74e3ef03cb5100d6306bf55f9220308976 Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:44 2015 +0800 Fourth Commit commit a285de0f648dd807dda329e2d2079ef20cf59118 Author: Andrew Er <andrew@test.com> Date: Sun May 31 12:30:30 2015 +0800 Third Commit - Changed Author commit 1ffce288fa200abbac4d0789dc181b4e2f2f8cbd Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:20 2015 +0800 Second Commit commit 0ba19e07c5b4e5b2372a51382b910844c81bbefa Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:11 2015 +0800 First Commit

    Also, note the commit hash after the modified commit has been changed as well. In this example, the Fourth commit's hash has also been modified.

  9. Once you're happy with the change, it is time to push the new content to Bitbucket Server. There are two ways about this because this is a non-fast-forward push as the tip of the current branch on your local repository is behind Bitbucket Server's counterpart. In order the continue, you would either:

    1. Have to integrate the changes with your remote.

      • This will cause the repository to have duplicate additional commits

      • For this, you would need to perform a git pull. Only then, you can push the new content to Bitbucket Server.

      • git log would show like this as per the example

        Xyrenus ~/Desktop/repo_sample (master) $ git pull Merge made by the 'recursive' strategy. Xyrenus ~/Desktop/repo_sample (master) $ git log commit 09db367da8147cf42065caa945a85ec829ff312b Merge: 99d6bc7 3b0065e Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 13:11:23 2015 +0800 Merge branch 'master' of https://<repository>/Andrew/repo commit 99d6bc74e3ef03cb5100d6306bf55f9220308976 Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:44 2015 +0800 Fourth Commit commit a285de0f648dd807dda329e2d2079ef20cf59118 Author: Andrew Er <andrew@test.com> Date: Sun May 31 12:30:30 2015 +0800 Third Commit - Changed Author commit 3b0065e6a00729f3ee753c162b545f101feb7277 Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:44 2015 +0800 Fourth Commit commit 1f096bfe7503b2805af64b69c9fe12c059ec9000 Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:30 2015 +0800 Third Commit commit 1ffce288fa200abbac4d0789dc181b4e2f2f8cbd Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:20 2015 +0800 Second Commit commit 0ba19e07c5b4e5b2372a51382b910844c81bbefa Author: Bitbucket Server Admin <bitbucket@admin.com> Date: Sun May 31 12:30:11 2015 +0800 First Commit Xyrenus ~/Desktop/repo_sample (master) $ git push origin master Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 570 bytes | 0 bytes/s, done. Total 4 (delta 2), reused 0 (delta 0) To https://<repository>/Andrew/repo.git 3b0065e..09db367 master -> master

    2. Perform a Push with --force-with-lease flag

      git push origin master --force-with-lease
      • Note that this will completely overwrite all commits to Bitbucket Server.

      • Do not ever force push on a public repository.

      • Do not do this as that can break someone's pull.

      • This would be the least recommended way to push to Bitbucket Server.

      • Please take a backup copy of your Bitbucket Server Home Directory should you need to revert back to your previous state.

  10. Your new changes should have been reflected on the Bitbucket Server.

If the resolution does not work, please get in touch with Atlassian Support.

Updated on June 27, 2025

Still need help?

The Atlassian Community is here for you.