Reset/revert a whole branch to another branches state?

One way to achieve this is through git reset. While on branch B execute

git reset --hard A

Thereafter, branch B points to the head-commit of A. The --hard option resets the index and working tree so that all tracked files are reset to the version in branch A. The old HEAD commit-ID of A is stored in .git/ORIG_HEAD in order to allow undoing the change.

Alternatively – while not on branch B – you can delete branch B and re-created it like this:

git branch -d B     # delete branch B
git branch B A      # re-create branch B and let it point to the commit of branch A

Other than the first suggestion, this will leave the index and working tree untouched.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)