zoukankan      html  css  js  c++  java
  • Git Delete Last Commit

    Git Delete Last Commit_wangronghouyi_新浪博客

    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.

  • 相关阅读:
    HTML常用标签
    消息机制JMS
    一个Socket连接管理池(心跳机制)
    Java调用其他程序时waitFor()阻塞
    JDBC连接数据库
    mysql入门
    WebService到底是什么
    Netty详解
    Mongodb集群搭建
    JavaScript入门
  • 原文地址:https://www.cnblogs.com/lexus/p/2356688.html
Copyright © 2011-2022 走看看