标签:reset git How wrong branch commit your
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.
标签:reset,git,How,wrong,branch,commit,your 来源: https://www.cnblogs.com/GeniusLyzh/p/15563343.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。