Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "git describe" showing an older tag version on my clean git repo copy?

Some background:

I currently have two local git repos which point to the same origin/master project. The reason I have two git repos is so that I have a clean master copy that I can use whenever I need and the one copy which my sandbox where I can apply changes, commit, etc. It is probably overkill, but there are some advantages for me personally by having a duplicate local git copy.

A co-worker originally created a lightweight tag for 1.0.2, but we deleted it and re-tagged it as an annotated version with the same number. They committed the change via git push to the remote repo. I pulled down the latest changes on both my local git instances.

Our tags are as follows:

release-1.0.0
release-1.0.1
release-1.0.2

The Problem:

Here is the issue I can't figure out. My sandbox repo shows the latest tag version (release-1.0.2) when I run "git describe". This is what I expected. However, the clean repo copy, which I only do pulls from, shows the older tag (release-1.0.1) when I execute "git describe". I verified that both are pointing to the origin master. I did some more research and found an overstack solution that pointed me to running "git cat-file -t". Here is the difference I noticed:

git cat-file -t release-1.0.1 --> tag 
git cat-file -t release-1.0.2 --> commit

Why is my clean copy repo showing an older tag version when I run "git describe" unlike my sandbox repo? I can confirm that I can see release-1.0.2 listed if I run "git describe --tags" on the clean repo copy.

like image 991
lifesabeach Avatar asked Aug 25 '15 16:08

lifesabeach


1 Answers

A co-worker originally created a lightweight tag for 1.0.2, but we deleted it and re-tagged it as an annotated version with the same number. They committed the change via git push to the remote repo. I pulled down the latest changes on both my local git instances.

Unless you use the --tags flag, git describe is only concerned with annotated (as opposed to lightweight) tags. Here, the output of git cat-file indicates that you still have the old release-1.0.2 lightweight tag in your sandbox repo. The snag is that, by default, git pull itself will not fetch the newer, annotated tag of the same name and overwrite the older, lightweight one with it.

To solve the problem, first delete the lightweight tag locally by running

git tag -d release-1.0.2

in your sandbox repo, and then, run

git fetch

(or git pull, if you know what you're doing). The new release-1.0.2 annotated tag will then take the place of the old lightweight one. You can make sure of that by running git describe or

git cat-file -t release-1.0.2

which should now output tag (not commit).

like image 101
jub0bs Avatar answered Oct 22 '22 08:10

jub0bs