How can I rollback a github repository to a specific commit?
My github has 100 commits in it right now. I need to rollback the repository to commit 80, and remove all the subsequent ones.
Why? This repo is supposed to be for merging from miscellaneous users. A bunch of merges went in as commits from me, due to excessive editing. That was due to a mislabeling of my remote branches, where 3 developers were labeled as each other. I need to reset to that point, and then pull forwards.
I wanted to rebase, as in this example: How can I remove a commit on GitHub?
However, git wants me to do a lot of conflict management. Is there a simpler way?
git reset --hard <old-commit-id>
git push -f <remote-name> <branch-name>
注意:正如下面的评论中所写的, 在协作环境中使用它是很危险的:您正在重写历史
Another way:
Checkout the branch you want to revert, then reset your local working copy back to the commit that you want to be the latest one on the remote server (everything after it will go bye-bye). To do this, in SourceTree I right-clicked on the and selected "Reset BRANCHNAME to this commit".
Then navigate to your repository's local directory and run this command:
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v -f --tags REPOSITORY_NAME BRANCHNAME:BRANCHNAME
This will erase all commits after the current one in your local repository but only for that one branch.
To undo the most recent commit I do this:
First:
git log
get the very latest SHA id to undo.
git revert SHA
That will create a new commit that does the exact opposite of your commit. Then you can push this new commit to bring your app to the state it was before, and your git history will show these changes accordingly.
This is good for an immediate redo of something you just committed, which I find is more often the case for me.
As Mike metioned, you can also do this:
git revert HEAD
链接地址: http://www.djcxy.com/p/89502.html
上一篇: 在git中忽略修改(但未提交)的文件?