如何将 GitHub wiki 集成到主项目中
我希望将所有源代码和文档保存在一个 Git 存储库中。我已经将 GitHub 页面集成到我的主项目中,现在我想对 GitHub wiki 做同样的事情。
我知道 GitHub wiki 是普通的 Git 存储库。我的计划是将 wiki 作为远程添加到我的主存储库,并将所有内容保存在一个地方。然而,在 wiki 存储库中,所有内容都位于根目录中,因此会使我的主项目变得混乱。
处理这个问题的最佳方法是什么?
I want keep all my source code and documentation in one single Git repository. I already have the GitHub pages integrated into my main project and now I want to do the same with the GitHub wiki.
I know that GitHub wikis are plain Git repositories. My plan is to add the wiki as a remote to my main repository and keep everything in one place. However in the wiki repository everything is in the root directory and thus would clutter my main project.
What is the best way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您想要将 wiki 添加为子模块。相同的 Wiki Git 存储库作为远程连接,但位于具有自己的 .git 目录的子目录中。
在主存储库的根目录中,将 wiki 存储库添加为 wiki/ 目录中的子模块。
You want to add the wiki as a submodule. The same Wiki Git repository connected as a remote, but within a subdirectory with its own .git directory.
In the root of your main repository to add the wiki repository as a submodule in the wiki/ directory.
我觉得这一切都很乏味。在我看来,GitHub wiki 应该是主存储库的分支,或者至少应该可以使其成为一个选项。
尽管如此,我相信最好的解决方案是简单地将wiki移动到主存储库中,例如在
docs/
或wiki
中,使用子树合并。例如,假设您的存储库是you/proj
,您的 wiki 将位于:git://github.com/you/proj.wiki
。然后要将其合并到您的主存储库中,您可以这样做:您甚至可以让 wiki 保持一边工作以欢迎公众贡献,但然后根据您认为合适的情况将它们审查到您的主文档中。要在审核后合并新的更改,您可以这样做:
不幸的是,以其他方式合并更改有点棘手,无论如何,您应该一次性执行此操作,然后关闭 wiki,或重定向到存储库源。 ..
此外,这种方法的一个主要警告是 git log wiki/Home.md (例如)实际上并不显示 wiki 页面的历史记录。历史记录就在那里,但不知何故,git-log 无法跟踪它。这是与 git 子树相关的已知限制。解决此问题的另一种解决方案是执行一次过滤分支和定期合并以保留历史记录。
对我来说,将 wiki 作为主源代码树的一部分的主要优点是可以跨代码和文档协调拉取请求和更改。它还使得将文档与代码一起发送变得非常简单,而不是假设人们只是在线阅读它......
I find this all pretty tedious. In my opinion, GitHub wikis should be branches of the main repository, or at least it should be possible to make that an option.
Nevertheless, I believe the best solution is to simply move the wiki into the main repository, say in
docs/
orwiki
, using a subtree merge. For example, assuming your repository isyou/proj
, your wiki would be at:git://github.com/you/proj.wiki
. Then to merge it in your main repository, you would do:You can even keep the wiki working on the side to welcome public contributions there, but then vet them into your main documentation as you see fit. To merge the new changes in after review, you would do:
Unfortunately, merging changes the other way is somewhat trickier, and anyways, you should probably do this as a one time thing, then close the wiki, or redirect to the repo source...
Furthermore, a major caveat of this approach is that
git log wiki/Home.md
(for example) doesn't actually show the history from the wiki page. The history is there, but somehowgit-log
fails to track it. This is a known limitation related to git subtrees. Another solution to fix this would be to do afilter-branch
and a regular merge, one time, to keep history.For me, the main advantage of having the wiki as part of the main source tree is that pull requests and changes can be coordinated across code and documentation. It also makes it trivially simple to ship documentation with your code instead of assuming people will just read it online...
现在,到 2023 年,只需要 3 个命令:
这将创建一个从 docs 文件夹到 Github 上项目的 Wiki 存储库的链接。不要使用“git://”,它已经过时了!到处使用“https://”!
Now, in 2023, only 3 commands are needed:
This will create a link from the docs folder to your project's Wiki repository on Github. Don't use "git://", it's outdated! Use "https://" everywhere!
您可以使用 wiki 存储库创建一个 子模块或者定期进行获取并来回切换分支。
You could either create a submodule with the wiki repo in it or do a regular fetch and switch branches back and forth.
您可以将 wiki 存储库的副本放入主存储库中并并行使用它们:
这种方法结合了其他答案中建议的子模块和子树的优点,但它并没有使工作流程复杂化太多:它允许您您的主存储库中有 wiki 文件,可以在拉取请求中查看它们,并轻松地将它们推送到 wiki 或从 wiki 拉取。
要将现有存储库的内容添加到另一个存储库中,您需要暂时删除
.git
文件夹(否则 Git 会将其添加为子模块):这只是一次性问题,任何未来的文件都可以照常添加。
请注意,wiki 存储库的
.git
文件夹不会包含在您的主存储库中。这个答案描述了如何在克隆此类存储库后恢复它。
You could place a copy of a wiki repository into your main repository and work with them in parallel:
This method kind of combines the pros of submodules and subtrees suggested in other answers, but it doesn't complicate the workflow much: it allows you to have wiki files in your main repository, see them in pull requests and easily push them to or pull from the wiki.
To add a contents of an existing repository into another repository you'll need to remove the
.git
folder for a while (otherwise Git will add it as a submodule):This is only a one-time issue, any future files can be added as usual.
Note that the
.git
folder of a wiki repository won't be included into your main repository.This answer describes how to restore it after cloning such repository.
使用 子模块。此方法也可用于 GitHub 页面。
好处 - 作为主存储库脚本的结果更新 wiki。它将在主存储库中显示为链接目录,而不是常规目录。
Integrating a GitHub wiki into the main project is easier using a submodule. This method can also be used for GitHub pages.
Benefits - update the wiki as an outcome of a script from the main repo. It'll show up as a linked directory in the main repo rather than a regular directory.