I know how to revert to older commits in a Git branch, but how do I revert back to a branch's state dictated by a tag? I envision something like this:
git revert -bytag "Version 1.0 Revision 1.5"
Is this possible?
I know how to revert to older commits in a Git branch, but how do I revert back to a branch's state dictated by a tag? I envision something like this:
git revert -bytag "Version 1.0 Revision 1.5"
Is this possible?
Git tags are just pointers to the commit. So you use them the same way as you do HEAD, branch names or commit sha hashes. You can use tags with any git command that accepts commit/revision arguments. You can try it with git rev-parse tagname
to display the commit it points to.
In your case you have at least these two alternatives:
Reset the current branch to specific tag:
git reset --hard tagname
Generate revert commit on top to get you to the state of the tag:
git revert tag
This might introduce some conflicts if you have merge commits though.
git revert
just doesn't work. Looks like there's no way without forcing the push. Not the best for a control version software –
Floruit Use git reset:
git reset --hard "Version 1.0 Revision 1.5"
(assuming that the specified string is the tag).
If you are:
reset to a tag named reset-to-here
git reset --hard reset-to-here
push your change to the remote forcing by +
git push origin +master
You can use git checkout.
I tried the accepted solution but got an error, warning: refname '<tagname>' is ambiguous'
But as the answer states, tags do behave like a pointer to a commit, so as you would with a commit hash, you can just checkout the tag. The only difference is you preface it with tags/
:
git checkout tags/<tagname>
I've been looking for a solution to this problem for a long time. After a lot of research I can state that there is not a solution to this problem:
git reset --hard <tagname>
will change the history. It's not a revertgit revert <tagname>
will only apply the change of that specific commitgit revert <hash1>..<hash2>
won't work if there are merge. And even if you can specify the parent, this operation may be tedious if there are several merges. We have also to consider that every single revert must be wisely chosen and tested, if we don't want to break our branch. git rebase
and git cherry-pick
have the same problem.So this is the only thing that worked for me:
git checkout <tag name>
mkdir ../tmp
cp -r . ../tmp
git checkout master
cp -rf ../tmp/* .
rm -rf ../tmp
git commit -m "Revert"
git push
© 2022 - 2025 — McMap. All rights reserved.
git checkout <id> .
method from this answer. – Lipo