markdown 如何在Git中更改提交消息? - 首次发表于fullweb.io第55期

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何在Git中更改提交消息? - 首次发表于fullweb.io第55期相关的知识,希望对你有一定的参考价值。

# 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 .

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

⚠️ **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
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
```

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

以上是关于markdown 如何在Git中更改提交消息? - 首次发表于fullweb.io第55期的主要内容,如果未能解决你的问题,请参考以下文章

markdown 显示在特定git提交中更改的文件

markdown 显示在特定git提交中更改的文件

markdown Git提交消息规范

markdown AngularJS Git提交消息约定

如何在 git 中编辑任何提交的提交消息? [复制]

如何在 git 中编辑不正确的提交消息(我已推送)?