• 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.

  • 相关阅读:
    个人阅读作业
    个人阅读作业3
    阅读作业中软件开发书籍阅读后的一些体会
    个人项目代码复审
    读《移山之道-VSTS软件开发指南》
    北航MOOC客户端
    个人阅读作业3
    个人阅读作业2
    代码互审
    结对编程项目总结以及一些小小的体会
  • 原文地址:https://www.cnblogs.com/GeniusLyzh/p/15563343.html
Copyright © 2020-2023  润新知