Tag specific files in git

痞子三分冷 提交于 2021-02-08 10:13:47

问题


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?


回答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)


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



来源:https://stackoverflow.com/questions/42383328/tag-specific-files-in-git

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!