0

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?

Julian
  • 33,915
  • 22
  • 119
  • 174
  • 3
    A tag in Git is synonymous with a commit, which represents groups of files, not individual ones. I suspect that you don't even need the feature about which you are asking. If you clarify why you think you need this, maybe we can give a more direct answer. – Tim Biegeleisen Feb 22 '17 at 05:26
  • 1
    It *is* possible to tag a tree or a blob, but it rarely makes any sense to do so. Note that tagging a blob *does not* save a path name, as the blob is identified by its hash value. Tagging a tree would allow you to save a path name, but you might as well use the more-convenient machinery and just tag a commit. You can make a commit that has no history: the tag itself will preserve the commit. – torek Feb 22 '17 at 06:27

1 Answers1

1

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)?".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Instead of tags can I create release_branches for each release of the project? –  Feb 22 '17 at 18:05
  • @vikv a branch, like a tag, will reference a commit. Not a file. The difference is that, with a branch you can start making new modification and adding commits, while a tag is immutable and keep referencing the same commit. – VonC Feb 22 '17 at 18:07
  • thnks for your response, make sense. –  Feb 22 '17 at 18:52