Skip to content

Instantly share code, notes, and snippets.

@amalmurali47
Last active October 28, 2025 19:07
Show Gist options
  • Save amalmurali47/77e8dc1f27c791729518701d2dec3680 to your computer and use it in GitHub Desktop.
Save amalmurali47/77e8dc1f27c791729518701d2dec3680 to your computer and use it in GitHub Desktop.

Revisions

  1. amalmurali47 revised this gist Mar 11, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion edit_commit_history.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    1. Clone the repo.
    2. Use `git rebase -i --root`
    3. vim will open. Select the commits you want to modify by changing `pick` to `edit`. If you would like to change all the commits, enable line numbers with `set nu` and perform the following replace: `:1,Ns/pick/edit/g` (where `N` is the line number of the last line)
    3. vim will open. Select the commits you want to modify by changing `pick` to `edit`. If you would like to change all the commits, perform the following replace: `:%s/^pick/edit/g`. This command changes all instances of "pick" at the start of lines to "edit".
    4. You will now be shown all the selected commits one by one. Each commit message will be displayed. You have two options:
    - If you would like to keep the commit author details the same, do a `git rebase --continue`.
    - If you would like to change it to a different name/email, do `git commit --amend --reset-author`. If `--reset-author` is specified, it will use the details from your git config. (If you need to specify an alternate name/email, you can do so with `--author="John Doe <[email protected]>"`. If you would like to change the time to a previous date, you can do so with `--date "2 days ago"`.)
  2. amalmurali47 revised this gist Apr 19, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion edit_commit_history.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    git filter-branch --env-filter '
    OLD_EMAIL="[email protected]"
    OLD_NAME="oldusername"
    NEW_EMAIL="amalmurali47@gmail.com"
    NEW_EMAIL="newemail@example.com"
    # If the committer is updated but author isn't, set them both to author's name/email
    if [ "$GIT_COMMITTER_EMAIL" = "$CORRECT_EMAIL" ] && [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
  3. amalmurali47 revised this gist Apr 19, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions edit_commit_history.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    2. Use `git rebase -i --root`
    3. vim will open. Select the commits you want to modify by changing `pick` to `edit`. If you would like to change all the commits, enable line numbers with `set nu` and perform the following replace: `:1,Ns/pick/edit/g` (where `N` is the line number of the last line)
    4. You will now be shown all the selected commits one by one. Each commit message will be displayed. You have two options:
    - If you would like to keep the commit author details the same, do a `git rebase --continue`.
    - If you would like to change it to a different name/email, do `git commit --amend --reset-author`. If `--reset-author` is specified, it will use the details from your git config. (If you need to specify an alternate name/email, you can do so with `--author="John Doe <[email protected]>"`. If you would like to change the time to a previous date, you can do so with `--date "2 days ago"`.)
    - If you would like to keep the commit author details the same, do a `git rebase --continue`.
    - If you would like to change it to a different name/email, do `git commit --amend --reset-author`. If `--reset-author` is specified, it will use the details from your git config. (If you need to specify an alternate name/email, you can do so with `--author="John Doe <[email protected]>"`. If you would like to change the time to a previous date, you can do so with `--date "2 days ago"`.)
    5. Do the same for all the commits and finish the rebase.
    6. Perform `git push -f origin master` to force push all the changes to upstream, and verify everything is correct.
    7. Now the commit history would say "X authored, Y commited" for all the commits you did not modify. To fix this, run the following git-filter command:
  4. amalmurali47 revised this gist Apr 19, 2021. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion edit_commit_history.md
    Original file line number Diff line number Diff line change
    @@ -25,5 +25,7 @@ fi
    ```
    8. Now the `"X authored, Y commited"` problem will be fixed. However, this will also update the dates again. To fix that, run the following:

    ```git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' -f```
    ```
    git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' -f
    ```
    9. Finally, force-push again: `git push -f origin master` 🎉
  5. amalmurali47 created this gist Apr 19, 2021.
    29 changes: 29 additions & 0 deletions edit_commit_history.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    1. Clone the repo.
    2. Use `git rebase -i --root`
    3. vim will open. Select the commits you want to modify by changing `pick` to `edit`. If you would like to change all the commits, enable line numbers with `set nu` and perform the following replace: `:1,Ns/pick/edit/g` (where `N` is the line number of the last line)
    4. You will now be shown all the selected commits one by one. Each commit message will be displayed. You have two options:
    - If you would like to keep the commit author details the same, do a `git rebase --continue`.
    - If you would like to change it to a different name/email, do `git commit --amend --reset-author`. If `--reset-author` is specified, it will use the details from your git config. (If you need to specify an alternate name/email, you can do so with `--author="John Doe <[email protected]>"`. If you would like to change the time to a previous date, you can do so with `--date "2 days ago"`.)
    5. Do the same for all the commits and finish the rebase.
    6. Perform `git push -f origin master` to force push all the changes to upstream, and verify everything is correct.
    7. Now the commit history would say "X authored, Y commited" for all the commits you did not modify. To fix this, run the following git-filter command:

    ```
    git filter-branch --env-filter '
    OLD_EMAIL="[email protected]"
    OLD_NAME="oldusername"
    NEW_EMAIL="[email protected]"
    # If the committer is updated but author isn't, set them both to author's name/email
    if [ "$GIT_COMMITTER_EMAIL" = "$CORRECT_EMAIL" ] && [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
    then
    export GIT_COMMITTER_NAME="$OLD_NAME"
    export GIT_COMMITTER_EMAIL="$OLD_EMAIL"
    export GIT_AUTHOR_NAME="$OLD_NAME"
    export GIT_AUTHOR_EMAIL="$OLD_EMAIL"
    fi
    ```
    8. Now the `"X authored, Y commited"` problem will be fixed. However, this will also update the dates again. To fix that, run the following:

    ```git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' -f```
    9. Finally, force-push again: `git push -f origin master` 🎉