Richie
Richie

Reputation: 5199

GIT tagging did not work as expected

I have a question about an operation I have done in GIT. I have a repository which has two java projects in it and which currently sits at a certain tag.

Project 1 - MyTag 1.0.0
Project 2 - MyTag 1.0.0

So far so good.

Yesterday I checked in some code into the head and tagged the code again. Project 1 had some changes in it but Project 2 did not.

After my check in of the changes I tagged the repository again at MyTag 2.0.0. This is what I was expecting to see...

Project 1 - MyTag 2.0.0
Project 2 - MyTag 2.0.0

But instead I got...

Project 1 - MyTag 2.0.0
Project 2 - MyTag 1.0.0

Can anyone tell me why Project 2 did not get the new TAG?

I'm using TortoiseGit as my windows GIT client.

thanks

Upvotes: 1

Views: 172

Answers (1)

mounds
mounds

Reputation: 1383

Assumptions

  1. You have two directories in the root of your git repo, Project 1, and Project 2. (As an aside, I would suggest splitting these into different repos.)
  2. You are expecting that a git Tag will somehow track the state of all files in a particular commit.

Answer

Project 2 was included in the tag. What you are seeing is git reporting that the last commit made to Project 2 was the commit pointed to by MyTag 1.0.0.

MyTag 2.0.0 still includes Project 2.....Project 2 just hasn't changed since MyTag 1.0.0. If you checkout MyTag 2.0.0 you get a snapshot of the entire repo at that point.

Background

Tags are pointers to a commit. They point either
a) Directly (lightweight tags) or
b) Via a tag object which then points to a commit (annotated tags).

MyTag 2.0.0 points to a commit (Lets say C2) that contains change-sets in Project 1. I assume no files in Project 2 were changed and committed hence the tag doesn't relate directly to Project 2's files. MyTag 1.0.0 also points to a commit (Lets say C1).

Since MyTag 2.0.0 points to C2 which points to C1, all these changes are effectively pointed to by MyTag 2.0.0, and will be included when it is checked out.

MyTag 1.0.0 presumably points to a commit of changes to files in both Project 1/ and Project 2 directories.

Visually the commits look like this:

* C3 ---> C2 ---> C1 ---> init
         /        /
        /        /
  MyTag 2.0.0   /
               /
          MyTag 1.0.0

Bear in mind, I'm not using TortoiseGit so I can't see precisely what you are seeing. However the concept I've explained above of how git tags point to commits explains why any git client would show a similar result for what you've described. I performed your described commits and tags in a test repo and I get a similar (correct) result in SourceTree.

Upvotes: 2

Related Questions