[英]How can I commit specific directory to a different than a working branch on git?
I have a simple static website, based on HTML 5 boilerplate and the whole thing is in a github repository. 我有一个基于HTML 5样板的简单静态网站,整个内容都在github存储库中。 The project structure is something like this
项目结构是这样的
build
css
img
js
publish # this directory isn't in source control!
...
index.html & other files
Basically what I do is run a build script ( from HTML 5 boilerplate ) that compiles all the HTML/CSS/JS into the publish
directory, which isn't in the git repository . 基本上,我要做的是运行一个构建脚本( 从HTML 5样例开始 ),该脚本将所有HTML / CSS / JS编译到git存储库中没有的
publish
目录中 。
Now what I want to do, is make use of GitHub pages and be able to use the publish
directory output as a GitHub page. 现在,我要做的就是利用GitHub页面,并能够将
publish
目录输出用作GitHub页面。
The way GitHub pages work, is that you create a clean separate branch named gh-pages
, which will contain the final content. GitHub页面的工作方式是创建一个干净的单独分支
gh-pages
,其中将包含最终内容。 What I want to do, is to be able to on demand commit the current publish
directory into the gh-pages
branch , but I also want to keep it in the main .gitignore
file so it won't get pushed into the source repository. 我想要做的是能够按需将当前
publish
目录提交到gh-pages
分支中 ,但我也想将其保留在主.gitignore
文件中,以免将其推送到源存储库中。
I want to do this to kinda preview the current state of the project. 我想这样做是为了预览项目的当前状态。
in short: I need to commit one directory to a separate branch, so it's root will be the same as contents of that one directory. 简而言之: 我需要将一个目录提交到一个单独的分支,因此其根目录将与该目录的内容相同。
publish/css
will become just css
on the gh-pages
branch publish/css
将变成gh-pages
分支上的css
Since .gitignore
is versioned as well, just don't put the publish/
directory in the gh-pages
branch's .gitignore
file. 由于
.gitignore
已版本化,因此请勿将publish/
目录放在gh-pages
分支的.gitignore
文件中。 Then, you can just do something like this: 然后,您可以执行以下操作:
ORIG_HEAD="$(git name-rev --name-only HEAD)" git checkout gh-pages && mv publish/* . && git commit -am "automatic update" && git checkout "$ORIG_HEAD"
It does get tricky since you're wanting to do things in the root directory rather than a subdirectory. 它确实很棘手,因为您想在根目录而不是子目录中执行操作。 Another option would be to simply maintain a separate clone of the same repository in a different directory, that is always on the
gh-pages
branch. 另一个选择是简单地将同一存储库的单独克隆保存在不同目录中,该目录始终位于
gh-pages
分支上。 You could have your script just write the files to there instead of to publish/
and then just commit in that clone. 您可以让脚本只将文件写入那里,而不是
publish/
,然后提交该克隆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.