简体   繁体   English

如何将特定目录提交到与git上工作分支不同的目录?

[英]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.

相关问题 Git:如何将工作目录与分支的特定提交同步 - Git: How to sync working directory with a specific commit of a branch 使用Git,如何将工作副本中的某些更改提交到其他分支? - With Git, how can I commit some changes in the working copy to a different branch? 如何合并来自不同分支的 git commit? - How can i merge a git commit from a different branch? 如何将 git 分支上的标签移动到不同的提交? - How can I move a tag on a git branch to a different commit? Git:我可以将我的工作目录提交到新分支而不将其提交给当前分支吗? - Git: Can I commit my working directory to a new branch without committing it to a current branch? 什么样的GIT命令序列可以可靠地将工作目录更新为特定的代码分支/标记/提交? - What sequence of GIT commands can reliably update a working directory to a specific branch/tag/commit of code? Git -- 将先前的提交克隆到与本地工作目录不同的文件夹中 - Git -- cloning a previous commit in a different folder than local working directory 我如何获得工作目录内容,就像在特定提交时一样 - How can I get working directory content as it was at specific commit GIT - 我可以将分支合并到特定的提交 - GIT - Can I merge a branch up to a specific commit 如何通过Git中的其他推送提交对特定分支进行单个提交? - How can I make a single commit of specific branch from other pushed commits in Git?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM