當(dāng)我們已經(jīng)commit提交過(guò)一次了,然后發(fā)現(xiàn)還有些代碼沒(méi)改完,這個(gè)時(shí)候,很多童鞋都會(huì)考慮,再commit一次就行了,但是在git記錄中就會(huì)出現(xiàn)兩條commit,其實(shí)問(wèn)題不大,但是如果有很多這種情況,就會(huì)使git變得混亂不堪,那么此時(shí)最好的情況,就是將多條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
執(zhí)行此條命令后,會(huì)發(fā)現(xiàn)commit的hash值改變了,但是message內(nèi)容并沒(méi)有發(fā)生變化,并且最重要的是只有一條commit記錄。
2、git commit —amend -m "xxx"
當(dāng)你還需要修改上一條commit的message時(shí),就把—no-edit去掉, 加上 -m "xxx",就可以啦
補(bǔ)充:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-601503.html
當(dāng)使用git commit 在bash進(jìn)入文件時(shí),可以直接修改所屬內(nèi)容,修改完后,使用 git commit --amend提交.文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-601503.html
到了這里,關(guān)于有趣且重要的Git知識(shí)合集(8)git commit 重新提交(—amend —no-edit)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!