Git 子树标签

发布于 2024-08-19 03:33:57 字数 300 浏览 6 评论 0原文

我想使用子树合并将远程项目拉入我自己的 git 树中的目录中。我按照这里的说明进行操作: 使用子树合并

但我不知道如何签出标签。我想这是一个常见的请求 - 您想要引入外部项目,但获得源代码的安全标记版本。 子树合并解决方案效果很好,但我不确定如何获取我想要的标签?喜欢 git,但有时它会伤害我的头......

I want to use subtree merges to pull a remote project into a directory in my own git tree. I followed the instructions here:
using subtree merge

But I'm not sure how to checkout a tag. I imagine this is a common request - you want to pull in an external project but get a safe tagged version of the source.
The subtree merge solution works great, but I'm not sure how to get the tag I want? Love git, but sometimes it hurts my head....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

难以启齿的温柔 2024-08-26 03:33:57

当您输入 git tag 时,您将获得存储库中所有标签的列表。远程标签也显示在这里,我不知道它们是否可能冲突(没有检查),以及如何检查哪些标签导入到您的存储库。

但我检查的是,当您添加远程并从其他项目获取时,您会看到导入了哪些标签。然后您可以与该标签合并,例如:

git merge -s ours --no-commit v0.1.2 # instead of: Bproject/master (2)
git read-tree --prefix=dir-B/ -u v0.1.2 # instead of: Bproject/master (3)

它应该可以工作。

希望它能有点帮助,但我对 git 的了解并不像我希望的那么先进:-)

When you type git tag you'll get list of all tags in your repository. Remote tags also show here, and I don't know if they may conflict (didn't check that), and how to check what tags were imported to your repository.

But what I checked is that when you add remote and it fetches from other project, you see what tags are imported. Then you can merge with that tag, for example:

git merge -s ours --no-commit v0.1.2 # instead of: Bproject/master (2)
git read-tree --prefix=dir-B/ -u v0.1.2 # instead of: Bproject/master (3)

and it should work.

Hope it helps a little, but I'm not as advanced with git as I would like :-)

伊面 2024-08-26 03:33:57

GitHub 采用了 kernel.org 的 HowTo:http://help.github.com/subtree-merge /

GitHub has an adoption of the kernel.org's HowTo: http://help.github.com/subtree-merge/

回忆那么伤 2024-08-26 03:33:57

我在 Github 上的一个示例项目中做到了这一点,该项目名为 hesco/ hesco-weave如下:

我使用了curl,jq,剪切和 tail 命令在下面的示例中,因此您需要在运行示例之前拥有它们。

首先,找到项目的最后两个标签:

me@ubuntu: ~ $ curl -s https://api.github.com/repos/hesco/hesco-weave/git/refs/tags | jq -r ".[].ref" | cut -d "/" -f 3
v0.1
v0.2
v0.3
v0.4
v0.5
v0.6
v0.7
v0.8
v0.8.6
v0.8.7

me@ubuntu: ~ $ curl -s https://api.github.com/repos/hesco/hesco-weave/git/refs/tags | jq -r ".[].ref" | cut -d "/" -f 3 | tail -n 3
v0.8.6
v0.8.7

或者如果您有该项目的签出版本:

me@ubuntu: ~/github/hesco-weave (master) $ git remote -v
origin  https://github.com/hesco/hesco-weave.git (fetch)
origin  https://github.com/hesco/hesco-weave.git (push)
me@ubuntu: ~/github/hesco-weave (master) $ git tag -l
v0.1
v0.2
v0.3
v0.4
v0.5
v0.6
v0.7
v0.8
v0.8.6
v0.8.7

me@ubuntu: ~/github/hesco-weave (master) $ git tag -l | tail -n 2
v0.8.6
v0.8.7

引用的sha如下:

me@linux: ~ $ git ls-remote | tail -n 2
be74d8368acd4815b6863daded46a232944e0d84  refs/tags/v0.8.6
9181306caa304b4cf8b3764b1446c0c4006833d8  refs/tags/v0.8.7

第二,一个git存储库创建:

me@linux: ~  $ mkdir -p ~/test
me@linux: ~  $ cd ~/test
me@linux: ~/test  $ git init
Initialized empty Git repository in ~/test/.git/
me@linux: ~/test  $ touch README.md
me@linux: ~/test  $ git add .
me@linux: ~/test  $ git commit -m "README.md added"
[master (root-commit) b1ac90e] README.md added
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md
me@linux: ~/test (master) $ git log
commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: Me <[email protected]>
Date:   Wed Jun 14 13:02:05 2017 +0200

README.md added

第三,Github存储库的v0.8.6标签作为子树添加到创建的存储库中:

me@linux: ~/test (master) $ git subtree add --squash --prefix=weave https://github.com/hesco/hesco-weave.git v0.8.6

git fetch https://github.com/hesco/hesco-weave.git v0.8.6
warning: no common commits
remote: Counting objects: 543, done.
remote: Compressing objects: 100% (193/193), done.
remote: Total 543 (delta 306), reused 536 (delta 306), pack-reused 0
Receiving objects: 100% (543/543), 93.19 KiB | 0 bytes/s, done.
Resolving deltas: 100% (306/306), done.
From https://github.com/hesco/hesco-weave
 * tag               v0.8.6     -> FETCH_HEAD
Added dir 'weave'

跟踪信息:

me@linux: ~/test (master) $ git log
commit e5dc318c4437cd22ebddb9e82e8c419aef72a781
Merge: b1ac90e 19c0570
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave'

commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Squashed 'weave/' content from commit be74d83

    git-subtree-dir: weave
    git-subtree-split: be74d8368acd4815b6863daded46a232944e0d84

commit b1ac90efbfe5978bac52984c29e6ec7904ed9a75
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:05 2017 +0200

    README.md added

最后,带有较新标签v0的weave子树.8.7 与 git subtree pull 合并:

me@linux: ~/test (master) $ git subtree pull --squash --prefix=weave https://github.com/hesco/hesco-weave.git v0.8.7

warning: no common commits
remote: Counting objects: 548, done.
remote: Compressing objects: 100% (195/195), done.
remote: Total 548 (delta 311), reused 541 (delta 309), pack-reused 0
Receiving objects: 100% (548/548), 90.50 KiB | 0 bytes/s, done.
Resolving deltas: 100% (311/311), done.
From https://github.com/hesco/hesco-weave
 * tag               v0.8.7     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 weave/Changelog     | 1 +
 weave/Modulefile    | 2 +-
 weave/README.md     | 2 +-
 weave/metadata.json | 2 +-
 4 files changed, 4 insertions(+), 3 deletions(-)

跟踪信息:

me@linux: ~/test (master) $ git log
commit 9116e133c8d84de1df9883a8b5558a2350ebc86e
Merge: e5dc318 eb2e273
Author: me <[email protected]>
Date:   Wed Jun 14 13:03:16 2017 +0200

    Merge commit 'eb2e2733a75d59eb1adebf4755d5b11cb74e2b98'

commit eb2e2733a75d59eb1adebf4755d5b11cb74e2b98
Author: me <[email protected]>
Date:   Wed Jun 14 13:03:16 2017 +0200

    Squashed 'weave/' changes from be74d83..9181306

    9181306 make release used to update version to v0.8.7
    3871cf5 Update changelog, tag v0.8.6, fix link in README
    REVERT: be74d83 Update changelog, tag v0.8.6, fix link in README

    git-subtree-dir: weave
    git-subtree-split: 9181306caa304b4cf8b3764b1446c0c4006833d8

commit e5dc318c4437cd22ebddb9e82e8c419aef72a781
Merge: b1ac90e 19c0570
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave'

commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Squashed 'weave/' content from commit be74d83

    git-subtree-dir: weave
    git-subtree-split: be74d8368acd4815b6863daded46a232944e0d84

commit b1ac90efbfe5978bac52984c29e6ec7904ed9a75
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:05 2017 +0200

    README.md added


me@linux: ~/test (master) $ ll
total 4
-rw-rw-r-- 1 me me    0 Jun 14 13:01 README.md
drwxrwxr-x 8 me me 4096 Jun 14 13:03 weave

I did it for a sample project on Github which is called hesco/hesco-weave as follows:

I used curl, jq, cut and tail commands in the following examples, so you need to have them before running the examples.

First, the two last tags of the project are found :

me@ubuntu: ~ $ curl -s https://api.github.com/repos/hesco/hesco-weave/git/refs/tags | jq -r ".[].ref" | cut -d "/" -f 3
v0.1
v0.2
v0.3
v0.4
v0.5
v0.6
v0.7
v0.8
v0.8.6
v0.8.7

me@ubuntu: ~ $ curl -s https://api.github.com/repos/hesco/hesco-weave/git/refs/tags | jq -r ".[].ref" | cut -d "/" -f 3 | tail -n 3
v0.8.6
v0.8.7

Or if you have a checkouted version of the project:

me@ubuntu: ~/github/hesco-weave (master) $ git remote -v
origin  https://github.com/hesco/hesco-weave.git (fetch)
origin  https://github.com/hesco/hesco-weave.git (push)
me@ubuntu: ~/github/hesco-weave (master) $ git tag -l
v0.1
v0.2
v0.3
v0.4
v0.5
v0.6
v0.7
v0.8
v0.8.6
v0.8.7

me@ubuntu: ~/github/hesco-weave (master) $ git tag -l | tail -n 2
v0.8.6
v0.8.7

the sha of refs are as follows:

me@linux: ~ $ git ls-remote | tail -n 2
be74d8368acd4815b6863daded46a232944e0d84  refs/tags/v0.8.6
9181306caa304b4cf8b3764b1446c0c4006833d8  refs/tags/v0.8.7

Second, a git repository is created:

me@linux: ~  $ mkdir -p ~/test
me@linux: ~  $ cd ~/test
me@linux: ~/test  $ git init
Initialized empty Git repository in ~/test/.git/
me@linux: ~/test  $ touch README.md
me@linux: ~/test  $ git add .
me@linux: ~/test  $ git commit -m "README.md added"
[master (root-commit) b1ac90e] README.md added
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md
me@linux: ~/test (master) $ git log
commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: Me <[email protected]>
Date:   Wed Jun 14 13:02:05 2017 +0200

README.md added

Third, the v0.8.6 tag of the Github's repository is added to the created repository as subtree :

me@linux: ~/test (master) $ git subtree add --squash --prefix=weave https://github.com/hesco/hesco-weave.git v0.8.6

git fetch https://github.com/hesco/hesco-weave.git v0.8.6
warning: no common commits
remote: Counting objects: 543, done.
remote: Compressing objects: 100% (193/193), done.
remote: Total 543 (delta 306), reused 536 (delta 306), pack-reused 0
Receiving objects: 100% (543/543), 93.19 KiB | 0 bytes/s, done.
Resolving deltas: 100% (306/306), done.
From https://github.com/hesco/hesco-weave
 * tag               v0.8.6     -> FETCH_HEAD
Added dir 'weave'

Trace info:

me@linux: ~/test (master) $ git log
commit e5dc318c4437cd22ebddb9e82e8c419aef72a781
Merge: b1ac90e 19c0570
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave'

commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Squashed 'weave/' content from commit be74d83

    git-subtree-dir: weave
    git-subtree-split: be74d8368acd4815b6863daded46a232944e0d84

commit b1ac90efbfe5978bac52984c29e6ec7904ed9a75
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:05 2017 +0200

    README.md added

Finally, the weave subtree with the newer tag v0.8.7 is merged with git subtree pull:

me@linux: ~/test (master) $ git subtree pull --squash --prefix=weave https://github.com/hesco/hesco-weave.git v0.8.7

warning: no common commits
remote: Counting objects: 548, done.
remote: Compressing objects: 100% (195/195), done.
remote: Total 548 (delta 311), reused 541 (delta 309), pack-reused 0
Receiving objects: 100% (548/548), 90.50 KiB | 0 bytes/s, done.
Resolving deltas: 100% (311/311), done.
From https://github.com/hesco/hesco-weave
 * tag               v0.8.7     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 weave/Changelog     | 1 +
 weave/Modulefile    | 2 +-
 weave/README.md     | 2 +-
 weave/metadata.json | 2 +-
 4 files changed, 4 insertions(+), 3 deletions(-)

Trace info:

me@linux: ~/test (master) $ git log
commit 9116e133c8d84de1df9883a8b5558a2350ebc86e
Merge: e5dc318 eb2e273
Author: me <[email protected]>
Date:   Wed Jun 14 13:03:16 2017 +0200

    Merge commit 'eb2e2733a75d59eb1adebf4755d5b11cb74e2b98'

commit eb2e2733a75d59eb1adebf4755d5b11cb74e2b98
Author: me <[email protected]>
Date:   Wed Jun 14 13:03:16 2017 +0200

    Squashed 'weave/' changes from be74d83..9181306

    9181306 make release used to update version to v0.8.7
    3871cf5 Update changelog, tag v0.8.6, fix link in README
    REVERT: be74d83 Update changelog, tag v0.8.6, fix link in README

    git-subtree-dir: weave
    git-subtree-split: 9181306caa304b4cf8b3764b1446c0c4006833d8

commit e5dc318c4437cd22ebddb9e82e8c419aef72a781
Merge: b1ac90e 19c0570
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave'

commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:25 2017 +0200

    Squashed 'weave/' content from commit be74d83

    git-subtree-dir: weave
    git-subtree-split: be74d8368acd4815b6863daded46a232944e0d84

commit b1ac90efbfe5978bac52984c29e6ec7904ed9a75
Author: me <[email protected]>
Date:   Wed Jun 14 13:02:05 2017 +0200

    README.md added


me@linux: ~/test (master) $ ll
total 4
-rw-rw-r-- 1 me me    0 Jun 14 13:01 README.md
drwxrwxr-x 8 me me 4096 Jun 14 13:03 weave
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文