I am very new to git. I am currently trying to get familiarized with it by using it to track changes in some excel files that I am maintaining to track some continuous activity I am involved with. All the files are in a single repository. I want to tag each file separately with their versions. Is this possible? So far what I found was the capability to tag the entire repository. If what I am trying to do is wrong, do advise me on the best practice.
Thanks in advance.
Edit
When I was doing this I deliberately deleted a previous tag to make the entire repository be tagged( as I did not find a way to tag single files) as v1.0. As I now want to reset the name of the tag with the file name and quite comfortable with the way things should happen, how can I rollback the deletion and rename the previous tag (the deleted tag)?
Technically you can tag the content of a single file without it's file name. But such tags are of limited use. Tags are expected to point to commits, and special tags to non-commits have very different behavior (you can't git checkout such a special tag). So I strongly suggest to never use non-commit tags.
To create a Git tag with a message, use the “git tag” command with the “-a” option for “annotated” and the “-m” option for message. Note : if you don't provide the “-m” option, your default text editor will open in order for you to type the tag message.
Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.
Technically you can tag the content of a single file without it's file name. But such tags are of limited use. Tags are expected to point to commits, and special tags to non-commits have very different behavior (you can't git checkout such a special tag). So I strongly suggest to never use non-commit tags.
When you want only some files to be tagged, it might be better to use a separate repo for them, or at least different branches, since git always looks at the full tree for it's operations.
If you still insist to create such a special tag you do:
> git ls-tree HEAD
040000 tree 2c186ad49fa24695512df5e41cb5e6f2d33c119b bar
100644 blob 409940768f2a684935a7d15a29f96e82c487f439 foo.txt
> git tag my-bar-tree 2c186ad49fa24695512df5e41cb5e6f2d33c119b
> git tag my-foo-file 409940768f2a684935a7d15a29f96e82c487f439
You can only tag a commit, e.g. a certain snap shot in the history of your repository. However, git stores the files as blobs and what you can do is to use git notes to add a note to a blob, like this:
$ git ls-tree HEAD
100644 blob 252f7c7df5bd181536a6c9d0f9c371ce1a5dd042 .gitignore
100644 blob 8150ada74aba86c983ac3f8f63ab26aaa76fdcb7 README
100644 blob c4b1ff6dcb2a8e50727df21ced8d2872cd91af79 TODO.txt
$ git notes add -m "Adding a note to TODO" c4b1ff6dcb2a8e507
$ git notes show c4b1ff6dcb2a8e507
Adding a note to TODO
However, note that this note (no pun intended :) )is only attached to this blob, so whenever the file changes a new blob will be created (with another sha1 hash value) and the new blob will not have this note.
Tags are placed on specific commits as opposed to the repository as a whole as you suggest in your question.
One way of doing what you are suggesting is making sure you only commit changes to a single file with each commit, then you can tag that commit with eg. file1-v1.0
to represent v1.0 of file1.
What are you trying to represent by tagging these commits though? That will influence any advice on how to better your process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With