In a previous tip, I shared why we don't use return types on controller actions.
Recently, I was helping a company upgrade their Laravel app to a newer version, and I was using Laravel Shift to do the upgrade.
I love how Shift uses atomic commits, so if there's anything I don't want to adopt, I can revert that single commit.
In this case, I wanted to revert the atomic commit introducing return types, but only for the app/Http/Controllers
folder.
All other folders could keep the return types, so I don't want to revert those.
Here's how I did it. Make sure to do this starting with a clean git status:
-
git revert -n <commit-hash>
This reverts the whole commit, but the -n
prevents it from committing the change.
The reverted changes are only staged, so we can work with the revert before committing it.
-
git reset
This unstages all the changes from the revert, so we can pick and choose just the files we want to revert.
-
git add app/Http/Controllers
We only want to revert the changes in the app/Http/Controllers
folder, so we add just that folder to be committed.
-
git commit -m "Revert return types for controllers"
We make the commit with a descriptive message.
-
git restore .
Finally, we restore all the other changes that were reverted, since we don't want to revert those. Success!
It would be nice if git revert
had the ability to work with a specific path, but it doesn't, so this is the next best thing.
Here to help,
Joel
P.S. Do you have a different way of doing this? Reply and share, or even better, join the community and discuss it with a bunch of fellow Laravel devs.