1

Question

Why can I not add a tag to two older commits?

git tag -a matlabTest cfa84dbb6dd3c2c9956421e723d2f99786f7b417
git tag -a matlabTest 45b3a4d83eece8a5adcb947392f15a14bd4b0e63

Instead I am getting:

fatal: tag 'matlabTest' already exists

It seems Git wants to just create a new tag rather than linking the tag to the commits? (see below for more detail).


Background

I have followed the guidelines in the git book: https://git-scm.com/book/en/v2/Git-Basics-Tagging, and here's what I tried (and failed):

I enter git log --pretty=oneline, showing three commits:

cfa84dbb6dd3c2c9956421e723d2f99786f7b417 Preparing to make changes to changes.py to fix
45b3a4d83eece8a5adcb947392f15a14bd4b0e63 Tests: wholeseq analysis differs to Matlab
a894da22e2eb1c03930829622656ffd6da5ce161 Initial python scripts for analysis

I create a tag git tag -a matlabTest and now I want to add "matlabTest" to two of the commits**. Specifically, the top and middle commit of the three shown above.

git tag -a matlabTest cfa84d
git tag -a matlabTest 45b3a4

Now in both cases I get the following error:

fatal: tag 'matlabTest' already exists

But when I show the 'matlabTest' flag by entering git show matlabTest I see that only the first commit was successfully tagged, I have truncated output since it is long, but at the end of the output I cannot see that both commits were tagged:

tag matlabTest
Tagger: *foo (I did not want to show personal information)*
Date:   Fri Nov 25 02:37:41 2016 +0200

After testing dnds.py by comparing whole-seq dN/dS output to MATLABs dnds() output, both using NG, dnds.py seems to have a calculation error. So I have started to make changes to changes.py

commit 45b3a4d83eece8a5adcb947392f15a14bd4b0e63
Author: *foo (I did not want to show personal information)*
Date:   Fri Nov 25 02:20:27 2016 +0200

*...<remainder of script>*

Extra background

**Why do I want to tag the two older commits? Because there is some silent error (inconsistency with previous software I wrote in MATLAB) that I am trying to debug, and it is being caused by either one of two scripts (changes.py and dnds.py) and each has a different commit (cfa84db and 45b3a4d8) pointing to it. I want to tag both commits to help me treat this bug in a systematic way.

hello_there_andy
  • 2,039
  • 2
  • 21
  • 51

2 Answers2

3

A tag always reference one commit (in Git or other VCS, where its role is to unambiguously identify a particular revision).
Here (Git), the commit represent the full repo state at a certain point in its history.

In your case, you have alternative to tagging:

it is being caused by either one of two scripts (changes.py and dnds.py) and each has a different commit (cfa84db and 45b3a4d8)

You can pinpoint the exact faulty commit with git bisect, assuming you can write a test which exhibit the bad behavior. That will detect the first commit which introduced the bug.

If you really have to mark multiple commits, check out git notes.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Tag name should be different when you used for two different commit.

You can use tag name matlabTest.1 and matlabTest.2 to distinguish them. Also you can git tag -a matlabTest.1 cfa84d -m ‘describe the difference’.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74