[英]Copy a directory and all its files from the master branch into a new branch with a different directory structure
Let's say I have a master
branch and a gh-pages
branch.假设我有一个
master
分支和一个gh-pages
分支。 The directory structure for master looks like this: master 的目录结构如下所示:
projects/
project-one/
src/
app.js
dist/
bundle.js
index.html
project-two/
src/
app.js
dist/
bundle.js
index.html
The directory structure for gh-pages
is blank, but I want it to look like this: gh-pages
的目录结构是空白的,但我希望它看起来像这样:
project-one/
bundle.js
index.html
project-two/
bundle.js
index.html
I've tried instructions detailed here我试过这里详细的说明
$ git checkout master
$ git checkout gh-pages project-one/dist
error
$ git checkout gh-pages -- project-one/dist
error
That should copy the dist folder into the gh-pages
branch but I get a error pathspec: file not found
error so I tried git pull
to sync to the remote, but this does not solve the problem.那应该将 dist 文件夹复制到
gh-pages
分支,但我收到一个error pathspec: file not found
错误,所以我尝试git pull
同步到远程,但这并不能解决问题。
Note that in order to make gh-pages
clean I used git rm -r
on the whole directory because I do not want gh-pages
directory structure to be inherited from master
.请注意,为了使
gh-pages
干净,我在整个目录上使用了git rm -r
,因为我不希望从master
继承gh-pages
目录结构。
How can I copy everything in each project/dist folder from the master branch into the gh-pages branch?如何将每个 project/dist 文件夹中的所有内容从 master 分支复制到 gh-pages 分支?
edit: tried git checkout gh-pages project-one/dist/**
which gave me a better error msg: error: pathspec 'dist/bundle.js' did not match any file(s) known to git.
编辑:尝试
git checkout gh-pages project-one/dist/**
这给了我一个更好的错误 msg: error: pathspec 'dist/bundle.js' did not match any file(s) known to git.
You're doing it backwards.你在倒退。 You need to be in the scope of the
gh-pages
branch and then do your checkout
operations:您需要在
gh-pages
分支的范围内,然后进行checkout
操作:
$ git checkout gh-pages
$ git checkout master dir/file1
I believe the only way you could copy from a branch to another branch and change directory (without of course doing the manual work after the copy) would be the following:我相信您可以从一个分支复制到另一个分支并更改目录(当然在复制后不进行手动工作)的唯一方法如下:
$ git show master:dir/file1 > new_location/file1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.