Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganized changing commit message docs #229

Merged
merged 4 commits into from
Oct 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -49,15 +45,15 @@ 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.
```shell
$ git push --force <em>example-branch</em>
```

**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.

Expand Down Expand Up @@ -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 <em>example-branch</em>
```

{% endwarning %}
Ruth-ikegah marked this conversation as resolved.
Show resolved Hide resolved

For more information on interactive rebase, see "[Interactive mode](https://git-scm.com/docs/git-rebase#_interactive_mode)" in the Git manual.

Expand Down