简体   繁体   English

移动git repo上下文的最佳方法是什么?

[英]What is the best way to move the context of a git repo?

I currently have a git repo for a Jekyll blog that publishes to GitHub Pages. 我目前有一个发布到GitHub Pages的Jekyll博客的git repo。 When I set this up initially I initialized git at the root of the blog directory. 最初设置时,我在博客目录的根目录下初始化了git。 This means I'm committing and pushing all the Jekyll source files rather than only the static rendered content. 这意味着我要提交并推送所有的Jekyll源文件,而不只是静态的渲染内容。 Basically, I want to push from 基本上,我想从

$~/writing/_site/

as the root rather than what I'm currently pushing from 作为根源,而不是我目前的推动力

$~/writing/

I would like to start pushing to the remote repo just the static content, leaving all the source files only on my local machine. 我想开始将静态内容推送到远程仓库,而将所有源文件仅保留在本地计算机上。 I've considered creating a local branch and changing things but I don't think that achieves my result. 我曾考虑过创建一个本地分支机构并进行更改,但是我认为这并不能达到我的目的。 It's not that I'm changing the content itself, but rather pushing a child directory rather than a parent directory. 不是我要更改内容本身,而是要推送子目录而不是父目录。

I assume I could issue 我想我可以发出

$ git push --force

from the parent directory and then initialize a repo at the child directory and push from it , but that seems like a crude ignorance at play. 从父目录,然后初始化处子目录回购并从中推,但是,似乎是在玩粗的无知。

I could git-push --force , copy the Jekyll source to another untracked directory, and then create a branch and git-rm all the source and git-mv the content from the child directory into the parent directory but this also feels like oil painting with a piece of bread. 我可以git-push --force ,将Jekyll源复制到另一个未跟踪的目录,然后创建一个分支,然后将所有源git-rmgit-mv内容从子目录复制到父目录,但这也感觉像油用一块面包绘画。

Assuming that you want to continue to have version control for the source code of your site, to do what you want, you'll need two completely separate Git repositories. 假设您要继续对网站的源代码进行版本控制,并执行所需的操作,则需要两个完全独立的Git存储库。 One to store the source code, and another one to store the static contents that are generated by Jekyll in the _site folder. 一个用于存储源代码,另一个用于存储Jekyll在_site文件夹中生成的静态内容。

  • repoA - Full Jekyll source code repoA-完整的Jekyll源代码
  • repoB - Just the static content repoB-只是静态内容

The workflow would be something like this: 工作流程如下所示:

  1. Make changes to repo A (eg write a new post) 更改回购A (例如,撰写新帖子)
  2. Commit changes on repo A 提交仓库A的更改
  3. Run jekyll to build your website (generates _site ) 运行jekyll建立自己的网站(产生_site
  4. (Optionally) push the changes somewhere, usually private (可选)将更改推送到某个地方,通常是私有的
  5. Delete all files and folders on repo B 删除存储库B上的所有文件和文件夹
  6. Move all contents from repo A \\_site to repo B \\ 将所有内容从\\_site A \\_site B \\
  7. Commit changes on repo B 提交仓库B的更改
  8. Push changes in repo B to GitHub pages 将仓库B中的更改推送到GitHub页面

You'll probably want to automate steps 5 to 8 as they are boring and repetitive. 您可能希望将第5步到第8步自动化,因为它们很无聊且重复。 For that there are a myriad of tools you can use, such as Rake , Gulp , Grunt , etc. 为此,您可以使用多种工具,例如RakeGulpGrunt等。

If you go with Rake, you may also want to take a look at jekyll-rakefile . 如果您选择Rake,则可能还需要看看jekyll-rakefile

Don't make the other site a git repository, and don't use git to transfer the static content. 不要将另一个站点设置为git存储库,也不要使用git传输静态内容。 As torek's comment states, git communicates everything that is checked in (and only what is checked in). 正如torek的评论所指出的那样, git传达了所有已签入的内容(以及仅签入的内容)。 Instead, after building, you should use another tool such as scp or rsync to transfer the content. 相反,在构建之后,您应该使用诸如scprsync类的其他工具来传输内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM