首页 » 信息技术 »

git commit --amend介绍

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

git commit --amend命令可以让我们修改项目的上一个commit,不管是少add了必须的文件,还是有typo(拼写错误)。

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 add,使用git commit --amend就是只是修改comments

$ 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”.

这一段比较有趣,git commit --amend存在的理由,就是以防出现忘记加某个文件,或者有typo的时候,让项目history看起来更好一些(用git log命令)。但是当你使用git reflog命令的时候,就什么都能看到。

本文链接:https://www.maixj.net/ict/git-commit-amend-21583

相关文章

留言区


前一篇:
后一篇:

栏目精选

云上小悟,麦新杰的独立博客

Ctrl+D 收藏本页

栏目


©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。

网站二维码
go to top