我是靠谱客的博主 寒冷太阳,这篇文章主要介绍有趣且重要的Git知识合集(8)git commit 重新提交(—amend —no-edit),现在分享给大家,希望可以做个参考。

当我们已经commit提交过一次了,然后发现还有些代码没改完,这个时候,很多童鞋都会考虑,再commit一次就行了,但是在git记录中就会出现两条commit,其实问题不大,但是如果有很多这种情况,就会使git变得混乱不堪,那么此时最好的情况,就是将多条commit合并在一起

示例:

首次提交:

复制代码
1
2
3
4
5
6
7
8
// hello.js const str = { hello: 'hello' } // git cmd + git add . + git commit -m "feat:新增hello属性" + git push origin

再次提交: 

复制代码
1
2
3
4
5
6
7
8
9
// hello.js const str = { hello: 'hello', world: 'world' } // git cmd + git add . + git commit --amend --no-edit + git push origin

1、git commit —amend —no-edit

执行此条命令后,会发现commit的hash值改变了,但是message内容并没有发生变化,并且最重要的是只有一条commit记录。

2、git commit —amend -m "xxx"

当你还需要修改上一条commit的message时,就把—no-edit去掉, 加上 -m "xxx",就可以啦

最后

以上就是寒冷太阳最近收集整理的关于有趣且重要的Git知识合集(8)git commit 重新提交(—amend —no-edit)的全部内容,更多相关有趣且重要的Git知识合集(8)git内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(95)

评论列表共有 0 条评论

立即
投稿
返回
顶部