有趣且重要的Git知识合集(8)git commit 重新提交(—amend —no-edit)

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

示例:

首次提交:

// hello.js
const str = {
    hello: 'hello'
}

// git cmd
+ git add .
+ git commit -m "feat:新增hello属性"
+ git push origin

再次提交: 

// 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",就可以啦

猜你喜欢

转载自blog.csdn.net/qq_39404437/article/details/128254056
今日推荐