zoukankan      html  css  js  c++  java
  • How to reset a commit

    How to reset a commit

    You could follow these steps to revert the incorrect commit(s) or to reset your remote branch back to correct HEAD/state.

    1.checkout the remote branch to local repo.

    git checkout your_branch_name
    

    2.copy the commit hash

    (i.e. id of the commit immediately before the wrong commit) from git log

    git log -n5
    

    should show something like this:

    commit 7cd42475d6f95f5896b6f02e902efab0b70e8038 "Merge branch 'wrong-commit' into 'your_branch_name'"
    commit f9a734f8f44b0b37ccea769b9a2fd774c0f0c012 "this is a wrong commit" 
    commit 3779ab50e72908da92d2cfcd72256d7a09f446ba "this is the correct commit"
    

    3.reset the branch to the commit hash copied in the previous step

    git reset <commit-hash> (i.e. 3779ab50e72908da92d2cfcd72256d7a09f446ba)
    

    4.run the git status to show all the changes that were part of the wrong commit.

    5.simply run git reset --hard to revert all those changes.

    6.force-push your local branch to remote and notice that your commit history is clean as it was before it got polluted.

    git push -f origin your_branch_name
    

    The end.

  • 相关阅读:
    inner join和join
    Java输入输出流
    数据库基础——并发控制
    逻辑题
    数据库基础——数据库设计
    JDBC
    XmlHttpRequest
    servlet乱码
    Tomcat缺少服务
    poj2388---求奇数个数字的最中间的数
  • 原文地址:https://www.cnblogs.com/GeniusLyzh/p/15563343.html
Copyright © 2011-2022 走看看