我想使用子树合并将远程项目拉入我自己的git树中的目录。我按照这里的说明操作: using subtree merge
但我不确定如何结帐标签。我想这是一个常见的请求 - 您想要引入一个外部项目,但获得一个安全的标记版本的源代码。 子树合并解决方案效果很好,但我不知道如何获得我想要的标签?喜欢git,但有时会伤到我的头......
答案 0 :(得分:3)
当您键入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先进: - )
答案 1 :(得分:2)
GitHub采用了kernel.org的HowTo:http://help.github.com/subtree-merge/
答案 2 :(得分:0)
我为 Github 上的示例项目做了这个,名为hesco/hesco-weave,如下所示:
我在以下示例中使用了curl,jq,cut和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 <me@linux.me>
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 <me@linux.me>
Date: Wed Jun 14 13:02:25 2017 +0200
Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave'
commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: me <me@linux.me>
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 <me@linux.me>
Date: Wed Jun 14 13:02:05 2017 +0200
README.md added
最后,带有较新标记v0.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 <me@linux.me>
Date: Wed Jun 14 13:03:16 2017 +0200
Merge commit 'eb2e2733a75d59eb1adebf4755d5b11cb74e2b98'
commit eb2e2733a75d59eb1adebf4755d5b11cb74e2b98
Author: me <me@linux.me>
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 <me@linux.me>
Date: Wed Jun 14 13:02:25 2017 +0200
Merge commit '19c0570a414c4fd1635444b7a937dfc41c93a847' as 'weave'
commit 19c0570a414c4fd1635444b7a937dfc41c93a847
Author: me <me@linux.me>
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 <me@linux.me>
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