git restore master branch
Situation: we need to deploy hotfix urgently, but master branch is broken by non completed features
Task: backup commits, rollback, fix
Switch to master and pull fresh code
git checkout master
git pullLook in Octopus Deploy which commit is deployed right now to production (in our case it was был ffa7b5a)
Revert
git revert ffa7b5a..HEAD --no-commit
git commit -m "revert back to 43d2f1b 5 aug"Note: in our case for revert we need to add -m 1 this flag which of the parent branches from merge commit to use
Then commit our fix
git commit -m "hotfix"Deploy everything to prod
And remove last two commits
git log --oneline -4
mpb:rabota.ua mac$ git log --oneline -4
89df2a908 (HEAD -> master) hotfix
00a2f9975 revert
3bc9cecf3 (origin/master_12.04.2019_99cc647, backup) Merge branch 'master' of https://bitbucket.org/rabotaua/rabota.ua
48bdc94f1 RUA-21250
git revert 89df2a908
git revert 00a2f9975
git commit -m 'remove 2 last commits'And once again applying hotfix
git cherry-pick 89df2a908