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

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

问题描述

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

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

我将 SVN 存储库与 Git-SVN 一起使用.我的工作流程是:

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.

现在我想用 git tag -a RC1 -m 'Release Candidate 1' 标记我的项目,但我只希望我的项目获得标记.

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.

我该怎么做?

推荐答案

TL;DR version

如果您知道树的 SHA-1,则可以标记特定目录(又名树),但通常不这样做&用那个标签做有用的事情并不容易.

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.

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

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.

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

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

然后我可以标记这些树之一(假设上面的 data 目录):

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

$git tag data-1.0 f888c44e16f7811ba69a245adf35c4303cb0d4e7

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

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
...    ...  ...                                         ...

要取回原始的 SHA-1:

To get back the original SHA-1:

$git rev-parse data-1.0
f888c44e16f7811ba69a245adf35c4303cb0d4e7

这一切对你有什么好处?没有那么多.但是,如果您愿意编写自己的脚本来重建树的内容,或者查找包含树的提交,那么它可能对您有用.(例如,this SO answer 可以适用于这样的目的).

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

但正如其他人所说,使用更适合 Git 的版本控制/标记模型可能会更轻松,而不是尝试调整现有模型.正如 shikjohari & 已经提到的那样其他人,如果您想要具有自己版本的项目内项目,请考虑 Git 子模块 代替.

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天全站免登陆