PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 27, 2022

[FIXED] How to commit only a specific directory to a remote branch? (deleting all other content)

 September 27, 2022     bitbucket, continuous-deployment, deployment, git, plesk     No comments   

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 and git push

Observations

  1. A warning that says it is already up-to-date
  2. 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:

  1. Pull the latest changes: git reset --hard HEAD; git fetch
  2. Go to your branch: git checkout deployment
  3. Delete unwanted files/directories (other than dist/): find * -maxdepth 0 -name 'dist' -prune -o -exec rm -rf '{}' ';'
  4. Stage deleted changes: git add .
  5. 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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing