Working off a commit 5 commits ago. How does one do this best?
This question already has an answer here:
if you haven't pushed this, you can do
git reset --hard a625c16a2985d06f10fb72db9e6952fdf51e5000
This will discard all the changes completely and forget they every happened. However, this will mean that you will have to do git push --force
if you've published this anywhere, which might be considered dangerous / antisocial.
If you want to avoid that you can do
git revert 8379fef8952c9fde4c4f8bb9b3fb5dab80a61bc9
...
git revert 2da2d26974d1ef57a02f3dfe2c7b5aa310f2efac
Which will cleanly backout all the changes, and you'll be able to push without --force. This does mean all your changes and reversions will be visible in the history.
如果你已经把你想要的提交作为分离的HEAD检出,你可以简单地执行git branch -f branchname && git checkout branchname
。
下一篇: 处理提交5提交前。 如何做到最好?