1

这似乎是一件简单的事情,但在网上找不到解决方案。首先,我知道我可能可以在终端上执行此操作,但我更喜欢使用Tower执行此操作。并非我所有的同事都会使用终端。我有一个存储库(https://github.com/jbryer/psabook/),我想使用 Github 页面。我希望主分支跟踪源(主要是降价文件)。我从这些文件构建了一个网站,并希望将其发布到 gh-pages 分支。我可以将它作为我的存储库的子目录仅针对该分支进行跟踪吗?

这是我从这篇文章中尝试过的:http: //blog.blindgaenger.net/generate_github_pages_in_a_submodule.html

我从 Github.com 创建了一个名为 psabook 的存储库。然后从命令行执行以下操作(如果重要,在 Mac 上):

mkdir foobar
cd foobar
git init
touch README
git add README
git commit -m "initial commit"
git remote add origin git@github.com:jbryer/psabook.git
git push origin master
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "Hello PSA Book" > index.html
git add .
git commit -a -m "first gh-page"
git push origin gh-pages
git checkout master
git submodule add -b gh-pages git@github.com:jbryer/psabook.git _site

输出是:

Cloning into '_site'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 6 (delta 0)
Receiving objects: 100% (6/6), done.
Checking connectivity... done.

继续...

git status

回来:

On branc master
Changes to be committed:
  (use "git reset HEADE <file>..." to unstage)

      new file: .gitmodules
      new file: _site

继续...

git commit -m "added gh-pages as submodule"
git push

正是这个命令我得到了一个错误(请注意,我也必须转义括号):

git submodule init

为路径“_site”注册的子模块“_site”(git@github.com:jbryer/psagook.git)

这是我得到的错误:

error: pathspec 'Submodule' did not match any file(s) known to git.
error: pathspec '(git@github.com:jbryer/psabook.git)' did not match any file(s) known to git.
error: pathspec 'registered' did not match any file(s) known to git.
error: pathspec 'for' did not match any file(s) known to git.
error: pathspec 'path' did not match any file(s) known to git.
Did you forget to 'git add'?
4

1 回答 1

1

您可以从分支中看到内容 (master和)。gh-branchmaster

您需要在您的分支中将您的声明gh-branch子模块(!) 。 这样,当您在分支中时,将显示为子文件夹。master
mastergh-branch

完成设置后(在命令行中),您可以从 Tower 管理所有内容。

有关子模块设置,请参阅“在 git 中将文件夹部署到分支的最简单方法是什么? ”。

gh-branch然后需要提交每个修改,并且您需要返回主文件夹(再次)提交,以便记录 gitlink(特殊输入模式 160000)。
这样,master分支的每个版本都知道gh-branch它应该使用哪个版本。


2016 年 8 月更新:更简单的 GitHub 页面发布现在允许将页面文件保存在同一分支的子文件夹中(不再gh-pages需要):

现在您可以在存储库设置中选择一个源,GitHub Pages 将在那里查找您的内容。

所以现在这更容易了:现在需要两个分支,你可以在一个分支中完成所有事情。

于 2014-04-16T06:43:25.827 回答