复制另一个分支上的目录内容

发布于 2025-01-19 08:11:00 字数 358 浏览 3 评论 0原文

我在 github 上有 2 个分支:

  • master
  • gh-pages

我的分支 master 具有目录 _site,其中包含所有我需要存储在 gh-pages 根目录下的文件。

我正在使用 git 命令: git checkout master -- _site

_site的内容复制到gh-pages分支。

我的问题是,我正在获取目录及其内容,而我只需要根目录上的内容。

这可能吗?

I have 2 branches on github:

  • master
  • gh-pages

My branch master has the directory _site which contains all the files that I need to be stored on the root of gh-pages.

I am using the git command:
git checkout master -- _site

To copy the contents of _site to the gh-pages branch.

My issue is that I am getting the directory and it's content while I need the content only on the root.

Is this possible?

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

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

发布评论

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

评论(1

|煩躁 2025-01-26 08:11:00

一种选择是将 gh-pages 设置为您自己的存储库的子模块。

这意味着将 gh-pages 分支内容添加为当前存储库的子文件夹,位于 master 分支中,使用 git 子模块
(除非,如此处所述,您选择 master 分支本身作为 GitHub Pages 的源

git checkout master
git submodule add -b gh-pages -- /remote/url/of/your/own/repo gh-pages
git commit -m "Add gh-pages branch as submodule"
git push

您将有一个 gh-pages 子文件夹,您可以随时更新该子文件夹:

git submodule update --remote

我的问题是,我正在获取目录及其内容,而我只需要根目录上的内容。

您将从主存储库生成网站内容,而不是在目录 _site 中,而是在目录 gh-pages 中(因此将直接拥有网站内容)。

One option is to set gh-pages as submodule of your own repository.

That means adding thegh-pages branch content as a subfolder of your current repository, in the master branch, using git submodule.
(unless, as explained here, you chose the master branch itself as source for GitHub Pages)

git checkout master
git submodule add -b gh-pages -- /remote/url/of/your/own/repo gh-pages
git commit -m "Add gh-pages branch as submodule"
git push

You will have a gh-pages subfolder, that you can update at any time with:

git submodule update --remote

My issue is that I am getting the directory and it's content while I need the content only on the root.

You would generate, from your main repository, the site content not in the directory _site, but in the directory gh-pages (which would thereforce have directly the site content).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文