Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens in Git to a tag when you amend the commit that was tagged?

Tags:

git

commit

tags

I have committed a few source files to my git repository and tagged it as a new version of my software. But I saw a mistake I had just made and used the "amend" feature to commit the corrected files.

Now, I see that the tag was not transferred to the new commit (the one made with the "amend" feature). But I can also see that the tag still exists...

I would like to know what happened to the tag. Is this behavior a bug? Is the tag linked to a commit which doesn't exist anymore ?

I know I can force the creation of the same tag on the new commit, but I believe there should be a better way (like a command line parameter on the commit using "amend").

like image 668
Joan Rieu Avatar asked Jun 29 '10 18:06

Joan Rieu


People also ask

What happens when you amend a commit?

The git commit –amend command lets you modify your last commit. You can change your log message and the files that appear in the commit. The old commit is replaced with a new commit which means that when you amend your old commit it will no longer be visible in the project history.

Can you update a tag in git?

Similar to this, sometimes, we are required to update the tags in Git. Updating a tag will take your tag to another commit. For example, we can update the tag v1. 1 to another commit depicting that the stable Version1.

Does amending a commit change the hash?

Amending a CommitIf you amend the commit message, or the files in a commit, this will change the git hash.


1 Answers

This is by design. Git tracks commits, tags, blobs and trees as SHA-1 hashes of their contents. They are simply pointers to the objects. The object that the tag points to is still there. This is the version of the commit before you amended it. Just delete the tag and create it again. Ensure that you let others that are using the repository know what you did if they started anything from that commit.

To get a good background of how git works, take a look at Scott Chacon's Rails Conference talk about git on gitcasts.com. Also, read the short book on git: progit.org/book.

like image 113
Adam Dymitruk Avatar answered Oct 27 '22 17:10

Adam Dymitruk