Search code examples
gitsvngit-svn

git for-each-ref does not match the actual number of tags


I'm following this instruction to try to migrate an existing svn repository to git. https://john.albin.net/git/convert-subversion-to-git

I cloned the repository using the command

git svn clone https://urltorepository.com/svn/repos-itservices/apps --no-metadata --authors-file=authors.txt --stdlayout testing

When I do git for-each-ref i get following:

f98b1954059631270b44ed3037d3d08127ab051a commit refs/remotes/tags/RE.15.03.00.00
181a447b465c34857c1091b06173d30f467c9941 commit refs/remotes/tags/RE.15.03.00.01
cfca76149b8f79749ef0e978b3628fdcf43955d0 commit refs/remotes/tags/RE.15.04.00.00
bc19d96df3a95ae82368ac2083dc1cb77b39a2e9 commit refs/remotes/tags/RE.15.05.00.00
9cdf10ed94bcd5f88f121cb7977da79551918a7f commit refs/remotes/tags/RE.15.11.00.00
3d51a5ca903965b6043744c4995b3c17268c516b commit refs/remotes/tags/RE.16.03.00.00
83e65bbc68435b5622691acbaeba7e575bed08e4 commit refs/remotes/tags/RE.16.04.00.00
281e7aab7adc0d73fc678a39524cd8b64130fdfa commit refs/remotes/tags/RE.16.05.00.00
...
...
0cbf2d48633b5c8d691bf4b93208f02de0cd94fa commit refs/remotes/tags/RE.17.11.00.00
b57de4c3bc4caf4c77f2deb5eb10121193d39122 commit refs/remotes/tags/RE.17.11.10.00
1be3ba34cc0c0f556f972c6407605b560ad32f57 commit refs/remotes/tags/RE.18.01.00.00
56199738b9b4c523c7fc5daf00a3b7bd111f34f7 commit refs/remotes/tags/RE.18.02.00.00_IRIS-MIG
436823909e35cc78813042e1a2181048628e006d commit refs/remotes/tags/RE.18.03.00.00
f4edf4871858f180de3bae7c6dd04d1281e7a0f0 commit refs/remotes/tags/RE.18.03.00.00_ROLLBACK
4e38260f293ceb77281f0f87bd5816b48d0df174 commit refs/remotes/tags/RE.18.04.00.00
fcd58a4f0abf1b8dbb7d9edc846a831b964b09e4 commit refs/remotes/tags/RE.18.05.00.00
4e8936901052fd84804c7587cdb9c21ab980fc0e commit refs/remotes/tags/RE.18.06.00.00
18d443117221769ebccd42a1b22b06e039984c81 commit refs/remotes/tags/RE.18.08.00.00
8bfcb5f9c0b8d27f84e00ed5a2c4574cf726b357 commit refs/remotes/tags/RE18.06.00.00
6bb64c124aa47361c1fb951e6f6132ca09900b3f commit refs/remotes/tags/backup
b84d777d172d56bb43a18f9216cdfd48715cc76f commit refs/remotes/tags/backup@15657
a071ef00e51484338d1d8ee378f63a891d5e327b commit refs/remotes/tags/mod-security-2.2.7-test
5b0bd14307822551d65f1eabf06a229ac80cb0f2 commit refs/remotes/tags/mod-security2.2.7-testing
80b983c042b9ce5ce4c4b79fe02f1e4dec4785c5 commit refs/remotes/tags/package
568bf833abe733ebed65a0f2274826745c1c20bd commit refs/remotes/tags/package@15657
67155be3306148cc726711ec69092af4eba10845 commit refs/remotes/tags/props
f14622fc103a2c6ad1836c8a5d747f13936f5f7a commit refs/remotes/tags/props@15657
2c44a37dd69f45c58aabca388266232cfbbf108a commit refs/remotes/tags/rp
720d43aba7666cd9727d049dc3e04bc9827e4523 commit refs/remotes/tags/rp@15657
6bb64c124aa47361c1fb951e6f6132ca09900b3f commit refs/remotes/tags/tmp
b84d777d172d56bb43a18f9216cdfd48715cc76f commit refs/remotes/tags/tmp@15657
12d372c97e17f10ec5daba08debaf3e0fa887356 commit refs/remotes/trunk

But when I check this folder I see only few tags in it

$> ls -a .git/refs/remotes/tags/
.   RE.17.08.00.00  RE.17.11.10.00  RE.18.01.00.01  RE.18.02.00.00_IRIS-MIG  RE.18.03.00.00_ROLLBACK  RE.18.05.00.00  RE18.06.00.00
..  RE.17.10.00.00  RE.18.01.00.00  RE.18.02.00.00  RE.18.03.00.00           RE.18.04.00.00           RE.18.06.00.00  RE.18.08.00.00

Can some one tell me why is there this difference?

UPDATE

I added this tags to my git and then did git push --tag

$> git for-each-ref --format='%(refname)' refs/remotes/tags | egrep "RE*" | cut -d / -f 4- | while read ref; do git tag -a "$ref" -m "$ref"; done
$> git tag
RE.12.04.00.00
RE.12.05.00.00
RE.12.06.00.00
RE.12.07.00.00
...
...
RE.18.02.00.00
RE.18.02.00.00_IRIS-MIG
RE.18.03.00.00
RE.18.03.00.00_ROLLBACK
RE.18.04.00.00
RE.18.05.00.00
RE.18.06.00.00
RE.18.08.00.00
RE18.06.00.00

Then in my git repository I have following:

enter image description hereenter image description here

As you can see all tags are related to the last commit


Solution

  • Refs (such as tags) can be stored as individual files in .git/refs/**, or they can be stored as "packed references" in the single file `.git/packed-refs


    UpdatE - question was edited to add some information about trying to add tags based on the RE* refs. At this point it appears you're really asking how to create tags for each of these refs; please state your actual question clearly instead of making us guess what you want to know.

    So: a tag is a ref that points to some object in the database, and that happens to be placed in the refs/tags/ namespace. By convention refs in this namespace should not "move around" (much if at all) and they become "names" for the objects they point to.

    The git tag command takes, as an argument, the ID of - or an expression that resolves to - the object to which the ref should point. You didn't give that argument, so it went with the default - which is HEAD (the commit that's checked out right now).

    (Because of the order of arguments you used, it may not seem obvious that you omitted the target. But what you gave was a -a option, then a tag name, then a -m option with an annotation matching the tag name.)

    Instead of

    git for-each-ref --format='%(refname)' refs/remotes/tags | egrep "RE*" | cut -d / -f 4- | while read ref; do git tag -a "$ref" -m "$ref"; done
    

    you could try

    git for-each-ref --format='%(refname)' refs/remotes/tags | egrep "RE*" | cut -d / -f 4- | while read ref; do git tag -a -m "$ref" "$ref" "refs/remotes/tags/$ref"; done
    

    (Note that because you're creating an annotated tag, the ref will actually point to a new TAG object, which in turn will point to the correct commit. This is normal, but be aware that the ref won't appear to point to the ID you might expect.)