有趣且重要的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",就可以啦

补充:

当使用git commit 在bash进入文件时,可以直接修改所属内容,修改完后,使用 git commit --amend提交.

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值