Help: Reset GIT branch to a specific commit
Written by Vlad 30 August 2016

“Reset GIT branch to a specific commit” is the first topic we would like to address in the Help section. Since many of us find ourselves in a situation when we want to reset the master branch to a specific commit of the master- or some other branch, we’ll take some time to write a short guide on how this can be done in a few steps.

RESET BRANCH TO A SPECIFIC COMMIT

git reset –hard 87a9789447846c6ff3275f93589fbab3c7b801ec (commit hash that we want to reset the branch to)
git checkout -b xx (we check out a fictive branch, which will become master)
git branch -m master old-master (rename current master to something else)
git branch -m xx master (rename fictive branch to master)
git branch -d –force old-master (delete old master – not needed anymore)
git merge -s ours origin/master (merge master branches, but prefer local data)
make some changes to test git.
git commit -m ‘test’ (if needed do git add . first)
git push –set-upstream origin master (set local master branch to track origin master branch)
git push
git pull
We have also made a package that automates this process via artisan: https://github.com/ivanciric/artisan-git-tools
Everyone is invited to contribute to join the development of various commands that further facilitate our work.

BACK
Tags: , , , , , ,

JOIN THE MAILING LIST