描述
git checkout 來源分支 -- 文件路徑
例如我想 將master
分支上的utils
文件夾複製到 work
分支
git checkout master -- utils
完整Git命令
- 複製master上的utils文件夾到work分支
#切換到work分支
$ git checkout work
Switched to branch 'work'
#將master上的utils文件夾複製到work分支
$ git checkout master -- utils
#保存修改
$ git add utils
#提交修改
$ git commit -m "Adding 'utils' directory from 'master' branch."
[work 9fcd968] Adding 'utils' directory from 'master' branch.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 utils/file
- 刪除master上utils文件夾(可選)
#切換到master分支
$ git checkout master
Switched to branch 'master'
#遞歸刪除utils目錄
$ git rm -r utils
rm 'utils/file'
#提交
$ git commit -m "Removing 'utils' directory."
[master c786f95] Removing 'utils' directory.
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 utils/file