# git commit --amend介绍

2019年6月3日 / 99次阅读
Git

This command takes your staging area and uses it for the commit. If you’ve made no changes since your last commit (for instance, you run this command immediately after your previous commit), then your snapshot will look exactly the same, and all you’ll change is your commit message.

$git commit -m 'initial commit'$ git add forgotten_file
\$ git commit --amend

It’s important to understand that when you’re amending your last commit, you’re not so much fixing it as replacing it entirely with a new, improved commit that pushes the old commit out of the way and puts the new commit in its place. Effectively, it’s as if the previous commit never happened, and it won’t show up in your repository history.

git commit --amend并不是完全地将上一个commit替换到，只是让它看起来没有发生过，不会出现在你的项目history中。

The obvious value to amending commits is to make minor improvements to your last commit, without cluttering your repository history with commit messages of the form, “Oops, forgot to add a file” or “Darn, fixing a typo in last commit”.

Ctrl+D 收藏本页