Search code examples
gittortoisegit

Tag specific files in git


I am new git, I want to tag specific files from branch. Example: I have file1, file2, file3, file4 in master and tagged these 4 files as V1.0 for my initial release

Now I have added file5 in next release and merged into master.
I have to tag only file5 in new tag as V2.0 not all the previous files (file1, file2, file3, file4).
Can this can be done in git?

Can anyone help me how to do this in git or any other solution where I can update my every release of my project?


Solution

  • Can this can be done in git?

    No, considering a tag represent (generally, see below) a commit (which is a reference to the all repo content, not to a file or a delta)

    http://rypress.com/tutorials/git/media/12-4.png
    Picture from Git Plumbing

    You can list the files which have changed between two tags though:

    git diff --name-only v1.0 v2.0
    

    To list only new files, add --diff-filter=A:

    git diff --name-only --diff-filter=A v1.0 v2.0
    

    That would return 'f5'.


    As mentioned in "How to Tag a single file in GIT", you can technically tag a single file or a single tree:

    > 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
    

    But any non-commit tag is won't be used as a regular commit tag (you canot checkout it for instance).
    Possible usage for those non-commit tags: "Why git tag a blob or a tree (or a tag)?".