Assuming, current branch is mainline. mainline and HEAD pointer are pointing to the latest commit.
git reset HEAD~1
git branch -f mainline HEAD~1
To the best of my understanding both the commands will :
bring mainline pointer to a previous commit along with HEAD pointer
Which one should we use from the above two and why?
Edit : As pointed in comments current branch cannot be the same for using the git branch -f mainline HEAD ~1 command.
as noted by @phd in his comment: the difference is that git reset
will only work on the active branch, while git branch -f ...
will refuse to change the active branch.
Otherwise, both commands will result in bringing the target branch to HEAD~1