Issue
I have a branch named deployment
and I want to push only the contents of the folder dist
to this branch in my remote repository, deleting all other content.
I have tried so far
- Flag
git push
with--prefix
cd dist
andgit push
Observations
- A warning that says it is already up-to-date
- Remote has everything in there (and not just the 'dist' folder)
How do I select only dist/
folder in my commit?
Solution
As I understand, you want to
Commit only a specific directory to a remote branch (deleting all other content)
Since deployment
is created (branched out) from a branch that has all the files, you will need to delete unwanted files in the deployment
branch. You can get to the desired state with the following steps:
- Pull the latest changes:
git reset --hard HEAD; git fetch
- Go to your branch:
git checkout deployment
- Delete unwanted files/directories (other than dist/):
find * -maxdepth 0 -name 'dist' -prune -o -exec rm -rf '{}' ';'
- Stage deleted changes:
git add .
- Commit & push to remote:
git commit -m "Commit message"; git push origin deployment
Hope it helps!
Answered By - nkshio Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.