From 6ff006211dde67bf6f7fcb94712617ff34d882ff Mon Sep 17 00:00:00 2001 From: Ruth-ikegah Date: Thu, 8 Oct 2020 02:54:25 +0100 Subject: [PATCH] Reorganized changing commit message docs --- .../changing-a-commit-message.md | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/content/github/committing-changes-to-your-project/changing-a-commit-message.md b/content/github/committing-changes-to-your-project/changing-a-commit-message.md index 91ff84f7f1..e9c3fa8525 100644 --- a/content/github/committing-changes-to-your-project/changing-a-commit-message.md +++ b/content/github/committing-changes-to-your-project/changing-a-commit-message.md @@ -13,13 +13,9 @@ versions: You can change the most recent commit message using the `git commit --amend` command. -{% warning %} - In Git, the text of the commit message is part of the commit. Changing the commit message will change the commit ID--i.e., the SHA1 checksum that names the commit. Effectively, you are creating a new commit that replaces the old one. -{% endwarning %} - -#### Commit has not been pushed online +### Commit has not been pushed online If the commit only exists in your local repository and has not been pushed to {% data variables.product.product_location %}, you can amend the commit message with the `git commit --amend` command. @@ -39,7 +35,7 @@ You can change the default text editor for Git by changing the `core.editor` set {% endtip %} -#### Amending older or multiple commit messages +### Amending older or multiple commit messages If you have already pushed the commit to {% data variables.product.product_location %}, you will have to force push a commit with an amended message. @@ -49,7 +45,7 @@ We strongly discourage force pushing, since this changes the history of your rep {% endwarning %} -**Amending the message of the most recently pushed commit** +**Changing the message of the most recently pushed commit** 1. Follow the [steps above](/articles/changing-a-commit-message#commit-has-not-been-pushed-online) to amend the commit message. 2. Use the `push --force` command to force push over the old commit. @@ -57,7 +53,7 @@ We strongly discourage force pushing, since this changes the history of your rep $ git push --force example-branch ``` -**Amending the message of older or multiple commit messages** +**Changing the message of older or multiple commit messages** If you need to amend the message for multiple commits or an older commit, you can use interactive rebase, then force push to change the commit history. @@ -102,10 +98,15 @@ If you need to amend the message for multiple commits or an older commit, you ca ``` 4. Save and close the commit list file. 5. In each resulting commit file, type the new commit message, save the file, and close it. -6. Force-push the amended commits. - ```shell - $ git push --force - ``` + +{% warning %} + +When you're ready to push your changes to GitHub, use the push --force command to force push over the old commit. +```shell +$ git push --force example-branch +``` + + {% endwarning %} For more information on interactive rebase, see "[Interactive mode](https://git-scm.com/docs/git-rebase#_interactive_mode)" in the Git manual.