git

Rebasing in git without losing tags

Rewriting commits, squashing them, eliminating them, forgeting blobs or just rebasing from master to make future merges less painful. Git comes equiped with all we need to rewrite history.

But! doing so will have the nasty side effect of changing our commit hashes, and our tags will be now referencing commits that are out of tree. As we want to make changes further and further away in the branch history, manually adjusting the tags to the new hashes can become really tedious.

Enter git rebasetags

Usage

Installation

Get the script from github and make it executable.

To do it in one step, paste the following on your terminal

If you don’t like installing to /usr/local/bin  using sudo,  just copy git-rebasetags  wherever you like. It will work as long as the file is in the $PATH with execute permissions.

Details

In case we are doing interactive rebasing, we will be presented with a bash shell where we can make any manual changes and finish (or abort) the rebase operation. Whenever we exit that shell, our tags will be reassigned to the new hashes.

Matching is performed based on the commit line. This means that, if we change it, we will still have to do manual adjustments, and the same goes whenever we have different commits with the same comment ( for example ‘Update README.md‘ ).

github

Keep in mind that we are still changing history, so forced pushes, merges, conflicts and such niceties will happen.
Remember to keep a checked out copy of the repo before trying this, and use with care.

Extra: using git-filter-branch

If you only want to do an action that can be automated with git-filter-branch, then you can use the –tag-name-filter option to restore tags to the each commit after the operation

 

 

Author: nachoparker

Humbly sharing things that I find useful
[ github dockerhub ]

One Commnet on “Rebasing in git without losing tags

Leave a Reply

Your email address will not be published. Required fields are marked *