Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active November 19, 2024 18:18
Show Gist options
  • Save nepsilon/156387acf9e1e72d48fa35c4fabef0b4 to your computer and use it in GitHub Desktop.
Save nepsilon/156387acf9e1e72d48fa35c4fabef0b4 to your computer and use it in GitHub Desktop.

Revisions

  1. nepsilon revised this gist Aug 2, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ git push origin master --force
    ```
    We edit the message like just above. But need to `--force` the push to update the remote history.

    ⚠️ **But! Force pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them.**
    ⚠️ **But! Force pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You should first check with them.**

    ## Not pushed + old commit:
    ```bash
    @@ -39,4 +39,4 @@ Then force push the commit:
    git push origin master --force
    ```

    ⚠️ **But! Remember re-pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them.**
    ⚠️ **But! Remember re-pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You should first check with them.**
  2. nepsilon revised this gist Jul 6, 2016. No changes.
  3. nepsilon revised this gist Jul 6, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -38,4 +38,5 @@ Then force push the commit:
    ```bash
    git push origin master --force
    ```
    ⚠️ **But! Remember re-pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them. **

    ⚠️ **But! Remember re-pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them.**
  4. nepsilon revised this gist Jul 6, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -17,6 +17,7 @@ git commit --amend
    git push origin master --force
    ```
    We edit the message like just above. But need to `--force` the push to update the remote history.

    ⚠️ **But! Force pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them.**

    ## Not pushed + old commit:
  5. nepsilon revised this gist Jul 6, 2016. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ git commit --amend
    git push origin master --force
    ```
    We edit the message like just above. But need to `--force` the push to update the remote history.
    Note that if others have already pulled your commits this may come with undesired effects.
    ⚠️ **But! Force pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them.**

    ## Not pushed + old commit:
    ```bash
    @@ -36,4 +36,5 @@ Edit your message with the same 3 steps process as above (`rebase -i`, `commit -
    Then force push the commit:
    ```bash
    git push origin master --force
    ```
    ```
    ⚠️ **But! Remember re-pushing your commit after changing it will very likely prevent others to sync with the repo, if they already pulled a copy. You shoul first check with them. **
  6. nepsilon revised this gist Jul 5, 2016. No changes.
  7. nepsilon revised this gist Jul 4, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # How to change your commit messages in Git?

    At some point you’ll find yourself in a situation where you need edit a commit message.
    That commit might already be pushed or not, be the most recent, or burried below 10 other commits, but fear not, git has your back 🙂.
    That commit might already be pushed or not, be the most recent or burried below 10 other commits, but fear not, git has your back 🙂.

    ## Not pushed + most recent commit:
    ```bash
  8. nepsilon revised this gist Jul 4, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ git rebase --continue
    ```
    Rebase opened your history and let you pick what to change. With edit you tell you want to change the message. Git moves you to a new branch to let you --amend the message. git rebase --continue puts you back in your previous branch with the message changed.

    ### Already pushed + old commit:
    ## Already pushed + old commit:
    Edit your message with the same 3 steps process as above (`rebase -i`, `commit --amend`, `rebase --continue`).
    Then force push the commit:
    ```bash
  9. nepsilon revised this gist Jul 4, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # How to change your commit messages in Git?

    At some point you’ll find yourself in a situation where you need edit a commit message.
    That commit might already be pushed or not, be the most recent, or burried below 10 other commits, but fear not, git has your back 🙂.

  10. nepsilon created this gist Jul 4, 2016.
    37 changes: 37 additions & 0 deletions git-change-commit-messages.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    At some point you’ll find yourself in a situation where you need edit a commit message.
    That commit might already be pushed or not, be the most recent, or burried below 10 other commits, but fear not, git has your back 🙂.

    ## Not pushed + most recent commit:
    ```bash
    git commit --amend
    ```
    This will open your `$EDITOR` and let you change the message. Continue with your usual `git push origin master`.


    ## Already pushed + most recent commit:

    ```bash
    git commit --amend
    git push origin master --force
    ```
    We edit the message like just above. But need to `--force` the push to update the remote history.
    Note that if others have already pulled your commits this may come with undesired effects.

    ## Not pushed + old commit:
    ```bash
    git rebase -i HEAD~X
    # X is the number of commits to go back
    # Move to the line of your commit, change pick into edit,
    # then change your commit message:
    git commit --amend
    # Finish the rebase with:
    git rebase --continue
    ```
    Rebase opened your history and let you pick what to change. With edit you tell you want to change the message. Git moves you to a new branch to let you --amend the message. git rebase --continue puts you back in your previous branch with the message changed.

    ### Already pushed + old commit:
    Edit your message with the same 3 steps process as above (`rebase -i`, `commit --amend`, `rebase --continue`).
    Then force push the commit:
    ```bash
    git push origin master --force
    ```