博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git Delete Last Commit
阅读量:6251 次
发布时间:2019-06-22

本文共 1029 字,大约阅读时间需要 3 分钟。

Git Delete Last Commit

Once in a while late at night when I ran out of coffee, I commit stuff that I shouldn't have. Then I spend the next 10 - 15 minutes googling how to remove the last commit I made. So after third time I wanted to make a record of it so I can refer to it later.

If you have committed junk but not pushed,

git reset --hard HEAD~1

HEAD~1 is a shorthand for the commit before head. Alternatively you can refer to the SHA-1 of the hash you want to reset to. Note that when using --hard any changes to tracked files in the working tree since the commit before head are lost.

If you don't want to wipe out the work you have done, you can use--soft option that will delete the commit but it will leave all your changed files "Changes to be committed", as git status would put it.

Now if you already pushed and someone pulled which is usually my case, you can't use git reset. You can however do a git revert,

git revert HEAD

This will create a new commit that reverses everything introduced by the accidental commit.

转载地址:http://emusa.baihongyu.com/

你可能感兴趣的文章
经典SQL语句大全
查看>>
Size转换工具类
查看>>
Mac控制台的渐变色玩一下!
查看>>
【C】自己写一个程序实现memcpy功能
查看>>
java微服务 k8s生产环境搭建
查看>>
go语言入门教程百度网盘:椭圆曲线加密算法ECC和椭圆曲线数字签名算法ECDSA
查看>>
使用Nginx搭建网页服务器
查看>>
大部分程序员都在抱怨自己工资低,但是真的工资低吗?
查看>>
Android 音视频开发 - 使用Camera采集视频
查看>>
探索iOS中Block的实现原理
查看>>
记录一次线上OOM情况排查过程
查看>>
91 Decode Ways
查看>>
工作中遇到的问题
查看>>
含着泪做Swift3迁移
查看>>
微信小程序海报生成组件封装
查看>>
AI伦理无法回避的5个问题:生物进化是否有方向?
查看>>
一半人将因人工智能失业?麻省理工科学家表示太可笑!
查看>>
‘生逢其时’的文化IP该如何借力科技?_创成汇
查看>>
java B2B2C Springcloud电子商城系统--------负载均衡(Load Balance)
查看>>
Java springcloud B2B2C o2o多用户商城 springcloud架构 (一)服务的注册与发现(Eureka)...
查看>>