我怎样才能提交特定的目录不同于git上的工作分支? [英] How can I commit specific directory to a different than a working branch on git?

查看:102
本文介绍了我怎样才能提交特定的目录不同于git上的工作分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的静态网站,基于,整个事情都在github存储库中。项目结构就像这样

  build 
css
img
js
发布#此目录不在源代码管理中!

...

index.html&其他文件

基本上我所做的是运行一个构建脚本(),将所有的HTML / CSS / JS编译成 publish 目录,它不在git仓库中

现在我想要做的是使用 GitHub pages ,并且能够使用 publish 目录输出作为GitHub页面。

GitHub页面的工作方式是创建一个名为 gh-pages 的干净的单独分支,它将包含最终内容。 我想要做的是,能够按需将当前发布目录提交到 gh-pages branch ,但我也想将它保存在主 .gitignore 文件中,这样它就不会被推入源存储库。



我想这样做可以预览项目的当前状态。

简而言之: 我需要将一个目录提交给一个单独的分支,因此它的根目录将与该目录的内容相同。 publish / css gh-pages css > branch

解决方案

由于 .gitignore 那么就不要把 publish / 目录放在 gh-pages 分支的中。 gitignore 文件。然后,你可以这样做:

  ORIG_HEAD =$(git name-rev --name-only HEAD) git checkout gh-pages&& mv publish / *。 &安培;&安培; git commit -am自动更新&& git checkout$ ORIG_HEAD

由于您希望在根目录中执行操作,目录而不是子目录。另一个选择是简单地将同一个存储库的单独克隆保存在不同的目录中,该目录始终在 gh-pages 分支上。您可以让脚本将文件写入那里,而不是写入 publish / ,然后在该克隆中提交。


I have a simple static website, based on HTML 5 boilerplate and the whole thing is in a github repository. 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.

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.

The way GitHub pages work, is that you create a clean separate branch named gh-pages, which will contain the final content. 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.

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

解决方案

Since .gitignore is versioned as well, just don't put the publish/ directory in the gh-pages branch's .gitignore file. 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. You could have your script just write the files to there instead of to publish/ and then just commit in that clone.

这篇关于我怎样才能提交特定的目录不同于git上的工作分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆