簡體   English   中英

將一個目錄及其所有文件從 master 分支復制到具有不同目錄結構的新分支中

[英]Copy a directory and all its files from the master branch into a new branch with a different directory structure

假設我有一個master分支和一個gh-pages分支。 master 的目錄結構如下所示:

projects/
    project-one/
        src/
            app.js
        dist/
            bundle.js
            index.html
    project-two/
        src/
            app.js
        dist/
            bundle.js
            index.html

gh-pages的目錄結構是空白的,但我希望它看起來像這樣:

project-one/
    bundle.js
    index.html
project-two/
   bundle.js
   index.html

我試過這里詳細的說明

$ git checkout master
$ git checkout gh-pages project-one/dist
error
$ git checkout gh-pages -- project-one/dist 
error

那應該將 dist 文件夾復制到gh-pages分支,但我收到一個error pathspec: file not found錯誤,所以我嘗試git pull同步到遠程,但這並不能解決問題。

請注意,為了使gh-pages干凈,我在整個目錄上使用了git rm -r ,因為我不希望從master繼承gh-pages目錄結構。

如何將每個 project/dist 文件夾中的所有內容從 master 分支復制到 gh-pages 分支?

編輯:嘗試git checkout gh-pages project-one/dist/**這給了我一個更好的錯誤 msg: error: pathspec 'dist/bundle.js' did not match any file(s) known to git.

你在倒退。 您需要在gh-pages分支的范圍內,然后進行checkout操作:

$ git checkout gh-pages
$ git checkout master dir/file1

我相信您可以從一個分支復制到另一個分支並更改目錄(當然在復制后不進行手動工作)的唯一方法如下:

$ git show master:dir/file1 > new_location/file1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM