存储库的子文件夹的Git标签 [英] Git tag for a subfolder of a repository

查看:117
本文介绍了存储库的子文件夹的Git标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Git导入SVN存储库。然后我创建了我自己的项目作为存储库中的子文件夹。



我使用SVN仓库和Git-SVN。我的工作程序是:


  1. git commit -ammessage

  2. git svn rebase

  3. git svn dcommit

现在我想用标签我的项目git tag -a RC1 -m'Release Candidate 1 ',但我只想让我的项目获得标签。



我该怎么做?


<如果你知道树的特定目录(又名树),可以标记特定的目录(aka树)。 SHA-1,但它并不经常完成&使用该标记不容易做有用的事情。



长答案



Git中的每个对象都有唯一的SHA -1。最常见的是,SHA-1指的是提交,但它们也可以指blob(文件内容)和树(目录结构和文件名/文件权限映射)。您可以阅读 Git Objects文档

例如,假设我位于存储库中的特定目录中。我可以运行 git ls-tree HEAD 来获取我的路径中的文件/目录及其SHA-1的列表:

  $ git ls-tree HEAD 
100644 blob ed76d466f5025ce88575770b07a65c49b281ca59 app.css
100644 blob ed58ee4a9be6f5b58e25e5b025b25e6d04549767 app.js
100644 blob e2bed82bd9554fdd89d982b37a8e0659fe82390a controllers.js
040000树f888c44e16f7811ba69a245adf35c4303cb0d4e7数据
100644个一滴d68aa862e4746fc9abd0132cc576a4df266b0a9d directives.js
100644一滴df0ae0e7288617552b373d21f7796adb8fb0d1b6的index.html
040000树fa9c05b1bb45fb85821c7b1c27925b2618d646ac谐音
100644一滴28e9eb6fe697cb5039d1cb093742e90b739ad6af services.js

然后,我可以标记其中一棵树(比如 data 目录):

  $ git tag data-1.0 f888c44e16f7811ba69a245adf35c4303cb0d4e7 

这个标签现在是tha的别名t SHA-1,我可以在任何接受树的SHA-1的地方使用它:

  $ git ls-tree  - rt data-1.0 
100644 blob 6ab0a52a17d14cbc8e30c4bf8d060c4ff58ff971 file1.json
100644 blob e097e393fa72007b0c328d67b70ba1c571854db0 file2.json
040000 tree 39573c56941fdd2fc88747a96bf871550f4affb2 subfolder1
... ... ... ...

取回原始的SHA-1:



<$






















<所有这些对你有什么好处?没有太多。但是,如果您愿意编写自己的脚本来重构树的内容,或者查找包含树的提交,那么它可能对您有用。 (例如,这个SO答案可能适用于此目的)。



但正如其他人所说的那样,使用Git更好的版本/标记模型,您可能会更容易一点,而不是尝试去适应现有的模型。正如shikjohari&其他人,如果你想要项目中的项目,有自己的版本,请考虑 Git Submodules 代替。

I use Git to import a SVN repository. Then I created my own project as a subfolder in the repository.

I use the SVN repository with Git-SVN. My working procedure is:

  1. git commit -am "message"
  2. git svn rebase
  3. git svn dcommit.

Now I want to tag my project with git tag -a RC1 -m 'Release Candidate 1', but I only want that my project gets the tag.

How can I do that?

解决方案

TL;DR version

It's possible to tag specific directories (aka trees) if you know the tree's SHA-1, but it's not often done & not easy to do useful things with that tag.

Long answer

Every object in Git has a unique SHA-1. Most commonly, SHA-1s refer to commits, but they can also refer to blobs (file contents) and trees (directory structures & filenames/file-permission mappings). You can read about it in the Git Objects documentation.

For example, suppose I'm in a particular directory in my repository. I can run git ls-tree HEAD to get the list of files/directories in my path, along with their SHA-1s:

$git ls-tree HEAD
100644 blob ed76d466f5025ce88575770b07a65c49b281ca59    app.css
100644 blob ed58ee4a9be6f5b58e25e5b025b25e6d04549767    app.js
100644 blob e2bed82bd9554fdd89d982b37a8e0659fe82390a    controllers.js
040000 tree f888c44e16f7811ba69a245adf35c4303cb0d4e7    data
100644 blob d68aa862e4746fc9abd0132cc576a4df266b0a9d    directives.js
100644 blob df0ae0e7288617552b373d21f7796adb8fb0d1b6    index.html
040000 tree fa9c05b1bb45fb85821c7b1c27925b2618d646ac    partials
100644 blob 28e9eb6fe697cb5039d1cb093742e90b739ad6af    services.js

I can then tag one of these trees (let's say the data directory above):

$git tag data-1.0 f888c44e16f7811ba69a245adf35c4303cb0d4e7

The tag is now an alias for that SHA-1 and I can use it wherever a SHA-1 for a tree is accepted:

$git ls-tree -rt data-1.0
100644 blob 6ab0a52a17d14cbc8e30c4bf8d060c4ff58ff971    file1.json
100644 blob e097e393fa72007b0c328d67b70ba1c571854db0    file2.json
040000 tree 39573c56941fdd2fc88747a96bf871550f4affb2    subfolder1
...    ...  ...                                         ...

To get back the original SHA-1:

$git rev-parse data-1.0
f888c44e16f7811ba69a245adf35c4303cb0d4e7

What good will all this do you? Not much as-is. However, if you're willing to write your own scripts to reconstruct the contents of a tree, or to find the commits containing a tree, then it might be useful to you. (e.g. this SO answer could be adapted for such a purpose).

But like others have said, you'll probably have an easier time using a versioning/tagging model that's works better with Git, rather than trying to adapt your existing model. As already mentioned by shikjohari & others, if you want projects-within-a-project, which have their own versions, consider Git Submodules instead.

这篇关于存储库的子文件夹的Git标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆