gpt4 book ai didi

git - 从 git 子树获取上游分支

转载 作者:太空狗 更新时间:2023-10-29 14:28:16 25 4
gpt4 key购买 nike

在尝试使用 git subtree 找出一个好的工作流程时,我想跟踪在添加 git 子树时使用的上游分支(通常不同于 master)。

更具体地说,假设您定义了以下 Remote 并用于获取它们:

  $> git remote add -f easybuild-easyblocks https://github.com/ULHPC/easybuild-easyblocks.git
$> git remote add -f easybuild-easyconfigs https://github.com/ULHPC/easybuild-easyconfigs.git
$> git fetch easybuild-easyblocks
$> git fetch easybuild-easyconfigs

可以看到不同的远程分支:

  $> git show-ref | grep -v tags | grep easybuild
f4b4752bcadd5dd44aa74ee03f4bd19b75810bdb refs/remotes/easybuild-easyblocks/develop
49a1e893160c6c1d2ad50109265e55586c377c1e refs/remotes/easybuild-easyblocks/master
173aa5cabddf998e2ad672135752a33875095f8b refs/remotes/easybuild-easyblocks/v1.8.x
49a1e893160c6c1d2ad50109265e55586c377c1e refs/remotes/easybuild-easyblocks/v1.9.x
770c5246667d7741c02d4e1f4d4a50fb8cd3fcbe refs/remotes/easybuild-easyconfigs/develop
d8422c6f7aace405f1089f178edabb9316629d4b refs/remotes/easybuild-easyconfigs/master
5f3be9e2d5cbb2844ebf74ede15e2c30a8b12705 refs/remotes/easybuild-easyconfigs/uni.lu
0382ff527360f1baa192bb92597552cc379bba68 refs/remotes/easybuild-easyconfigs/v1.8.0.x
d8422c6f7aace405f1089f178edabb9316629d4b refs/remotes/easybuild-easyconfigs/v1.9.x

现在假设你定义了两个新的git子树来跟踪远程easybuild-easyblocks的上游分支develop(分别是v1.8.0.x 用于远程 easybuild-easyconfigs):

  $> git subtree add --prefix easybuild/easyblocks  --squash easybuild-easyblocks/develop
$> git subtree add --prefix easybuild/easyconfigs --squash easybuild-easyconfigs/v1.8.0.x

您以一个干净的目录布局结束,其中 easybuild/* 在单独的目录中保存相应存储库的最新版本。

我现在可以通过运行检查所有分支的头部提交哈希:

 $> git branch -v -r --abbrev=40                                                                                                                                                                                                                                                 
easybuild-easyblocks/develop f4b4752bcadd5dd44aa74ee03f4bd19b75810bdb Merge pull request #314 from boegel/version_bump
easybuild-easyblocks/master 49a1e893160c6c1d2ad50109265e55586c377c1e Merge pull request #312 from hpcugent/develop
easybuild-easyblocks/v1.8.x 173aa5cabddf998e2ad672135752a33875095f8b Merge pull request #281 from boegel/1.8.2_release_notes
easybuild-easyblocks/v1.9.x 49a1e893160c6c1d2ad50109265e55586c377c1e Merge pull request #312 from hpcugent/develop
easybuild-easyconfigs/develop 770c5246667d7741c02d4e1f4d4a50fb8cd3fcbe Merge pull request #500 from fgeorgatos/contrib_qtop
easybuild-easyconfigs/master d8422c6f7aace405f1089f178edabb9316629d4b Merge pull request #544 from hpcugent/develop
easybuild-easyconfigs/uni.lu 5f3be9e2d5cbb2844ebf74ede15e2c30a8b12705 add Allinea-4.2-34164-Ubuntu-10.04-x86_64.eb
easybuild-easyconfigs/v1.8.0.x 0382ff527360f1baa192bb92597552cc379bba68 Merge pull request #473 from boegel/v1.8.0.x
easybuild-easyconfigs/v1.9.x d8422c6f7aace405f1089f178edabb9316629d4b Merge pull request #544 from hpcugent/develop

现在我想从子树中提取最新的更改。因此我运行:

 $>git fetch easybuild-easyblocks    # fetch latest changes of the remote before merging
$> git subtree pull --prefix easybuild/easyblocks easybuild-easyblocks develop --squash

$> git fetch easybuild-easyconfigs
$> git subtree pull --prefix easybuild/easyconfigs easybuild-easyconfigs v1.8.0.x--squash

是否有一种简单的方法来猜测/检查已用于设置子树的上游分支,以便我可以按照以下格式制作通用命令:

   git subtree pull --prefix <path/to/subtree> <subtree-remote> <subtree-branch> --squash

???

最佳答案

简短的回答是否定的。

但是,我正在认真考虑为 git 做一个贡献,让子树将它们最后的推/pull 目标写入配置文件。

您现在可以通过编写一个 git 钩子(Hook)来做类似的 hack,它保存使用了哪个存储库,并编写一个使用保存值的​​包装器命令。

子树文档吹嘘它缺少配置文件,并声明:

Unlike submodules, subtrees do not need any special constructions (like .gitmodule files or gitlinks) be present in your repository, and do not force end-users of your repository to do anything special or to understand how subtrees work. Reference: git-subtree.txt

我认为不需要配置来设置代码是件好事,但与此同时,拥有一个只是为运行参数较少的命令提供有意义的默认值也没什么坏处。

我目前正在实现 subtree support for tortoisegit ,我也面临着同样的问题。我想这样做,当您选择对文件夹进行子树推送或 pull 时,它可以记住上次推送或 pull 该文件夹的位置。现在我让 tortoisegit 写入一个配置文件,但它确实应该在核心命令上完成。 See the pull request discussion here.

关于git - 从 git 子树获取上游分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22485673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com