如何仅将特定目录提交到远程分支? (删除所有其他内容)
How to commit only a specific directory to a remote branch? (deleting all other content)
我有一个名为 deployment
的分支,我只想将文件夹 dist
的内容推送到远程存储库中的这个分支,删除所有其他内容。
我已经试过了
- 用
--prefix
标记 git push
cd dist
和 git push
观察结果
- 一个警告说它已经是最新的
- Remote 包含所有内容(而不仅仅是 'dist' 文件夹)
如何在我的提交中 select 只有 dist/
文件夹?
据我了解,您想
Commit only a specific directory to a remote branch (deleting all other content)
由于 deployment
是从包含所有文件的分支创建(分支出来)的,因此您需要删除 deployment
分支中不需要的文件。您可以通过以下步骤达到所需的状态:
- 拉取最新更改:
git reset --hard HEAD; git fetch
- 前往您的分行:
git checkout deployment
- 删除不需要的files/directories(dist/除外):
find * -maxdepth 0 -name 'dist' -prune -o -exec rm -rf '{}' ';'
- 阶段删除更改:
git add .
- 提交并推送到远程:
git commit -m "Commit message"; git push origin deployment
希望对您有所帮助!
我有一个名为 deployment
的分支,我只想将文件夹 dist
的内容推送到远程存储库中的这个分支,删除所有其他内容。
我已经试过了
- 用
--prefix
标记 cd dist
和git push
git push
观察结果
- 一个警告说它已经是最新的
- Remote 包含所有内容(而不仅仅是 'dist' 文件夹)
如何在我的提交中 select 只有 dist/
文件夹?
据我了解,您想
Commit only a specific directory to a remote branch (deleting all other content)
由于 deployment
是从包含所有文件的分支创建(分支出来)的,因此您需要删除 deployment
分支中不需要的文件。您可以通过以下步骤达到所需的状态:
- 拉取最新更改:
git reset --hard HEAD; git fetch
- 前往您的分行:
git checkout deployment
- 删除不需要的files/directories(dist/除外):
find * -maxdepth 0 -name 'dist' -prune -o -exec rm -rf '{}' ';'
- 阶段删除更改:
git add .
- 提交并推送到远程:
git commit -m "Commit message"; git push origin deployment
希望对您有所帮助!