1

I am new to this tag concepts. In main branch, i pulled the most recent commits with

git pull origin main

I pulled the remote tags with

git fetch --tags --force                               

Then, I created a tag locally

 git tag -a v2.2 -m "some message"

the problem is, when i checked the tags in VScode, the tag v2.2 is having the commits of v2.1. I want only the commits made after v2.1 to be present in the new tag. How can i do that ?

Hari Warshan
  • 153
  • 1
  • 8
  • 2
    In Git, every commit points to the entire history leading up to itself, and tags point to commits; there’s no excluding the history of 2.1 from the history of 2.2. Instead, to see what’s new in 2.2, you should use 2.1 as a reference point – for example, if it were `git diff`, `git diff v2.1..v2.2`. What did you do to “check the tags in VScode”? – Ry- Dec 09 '21 at 07:35
  • @Ry- If I do "git diff v2.1..v2.2" its showing the older changes which I commited before creating tag v2.1 as new changes. – Hari Warshan Dec 09 '21 at 07:55
  • @Ry- Thanks for pointing it out. in VSCode git source control, under tags section. anyways its solved – Hari Warshan Dec 11 '21 at 05:45

1 Answers1

1

You would need to add and commit first on your branch, before adding a tag.

If you tag right after a pull, you would tag the last fetched commit, which might be the one already tagged v2.1.

Don't forget, a tag references a single Git object (here a commit).
That commit, in turn, has a reference to a history of past commits (including the v2.1 one).


  • If I do "git diff v2.1..v2.2" its showing the older changes which I commited before creating tag v2.1 as new change

See "What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?"

git diff v2.1..v2.2 will show you what is in v2.2, and what is not in v2.2 compared to v2.1.

Check first if v2.1 commit is a direct descendant of v2.2 commit (ie, if they are on the same branch).

I made some commits (lets say 10 commits) in "Feature" branch , merged to "develop"(remote) via PR and then to "main" via PR(remote) from develop.

Now I need to create a tag (v2.2). So I pulled the main, created a tag pushed it to remote. when I checked the diff between v2.2 and v2.1, but there are like 20 commits.

I would recommend:

git fetch
git tag -a v2.2 -m "some message" origin/main
git push --tags

That way, you are sure to tag what is from the remote origin you just fetched, rather than your local main branch, which would include local commits of your own, not yet pushed.


The OP Hari Warshan clarifies in the comments:

I had some other commits which wasn't there in remote.
That is what caused the confusion.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Sorry if i sound dumb. I made some commits (lets say 10 commits) in "Feature" branch , merged to "develop"(remote) via PR and then to "main" via PR(remote) from develop . now I need to create a tag (v2.2). So I pulled the main, created a tag pushed it to remote. when I checked the diff between v2.2 and v2.1, but there are like 20 commits. – Hari Warshan Dec 09 '21 at 08:05
  • If depends if your local main had itself local unpushed commits when you `git pull`'ed origin/main to your main. – VonC Dec 09 '21 at 08:07
  • Thanks for pointing it out, i had some other commits which wasn't there in remote. thats what caused the confusion. – Hari Warshan Dec 11 '21 at 05:47
  • @HariWarshan OK. I have included your comment in the answer for more visibility. – VonC Dec 11 '21 at 21:12