Git subtree tags

做~自己de王妃 提交于 2019-12-07 03:06:38

问题


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


回答1:


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




回答2:


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




回答3:


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 <me@linux.me>
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 <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

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


来源:https://stackoverflow.com/questions/2124044/git-subtree-tags

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