문제

I have a server with a bare git repository that I push to for live deployment. It has a simple post-receive hook that updates my server code with the latest on master.

I sometimes need to revert to a specific past commit when bugs are found on the production server (I test myself locally, but I don't catch everything). Is there a nice* way to revert to a past commit with this setup?

*By nice I mean a one-liner like pushing to the bare repository: git push prod master

도움이 되었습니까?

해결책

If you want to keep your mistake in the history, this will add commits which compensate the commits you specify. (master must be checked out locally) For example, if you want to revert the last commit, you can use:

git revert master
git push origin master

If you want to remove the last 2 commits from history (master must be checked out locally):

git reset master~2
git push -f origin master

Or without changing anything local, this should work as well:

git push -f origin master~2:master

The last two will force-update the master to the third from last master commit. Which is problematic if someone else already pulled the commits you are removing.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top