I’ll use this post as a personal reference for useful GIT commands as I find them. Hopefully they’ll help you also.
You have accidentally made a few commits to a branch and you wish to undo them so they are identical to the origin. You’ll probably see something like this when you run
# On branch devel
# Your branch is ahead of ‘origin/devel’ by 2 commits.
This resets your current branch to an identical state of the current HEAD of the origin <branch>
You have created a branch B from branch A and made a few commits. Assuming you write useful commit messages it’s useful for other developers to see the changes you’ve made and the features you’ve added since you branched. To do this type the following command:
git log $(git merge-base A B)..B #
List all branches, ordered by last-commit date (with last-commit date visible):
for k in `git branch|perl -pe s/^..//`;do echo -e `git show –pretty=format:”%Cgreen%ci %Cblue%cr%Creset” $k|head -n 1`\\t$k;done|sort -r
Short Version: This script will allow you to manage your wordpress plugins in git, and deploy them to wordpress.org SVN.
Recently at work I was required to build a wordpress plugin. After trawling through the documentation to figure out what I needed to do, it became apparent that to get my plugin listed in the WordPress plugins directory I would be required to host the code in their SVN repository. Along with most developers nowadays, I’ve switched to Git (for numerous reasons), so I was left with the dilemna of how to manage my plugin within git and host it on Github, but sync all changes to the SVN repository whenever a new version was ready. There’s quite a lot of work involved when trying to do this so I wanted to automate the whole thing. The result is a bash script shown below which will:
- Check that the version numbers in your readme.txt match up with those in your PHP file.
- Commit the latest outstanding changes to your git repository if any are left
- Push the latest changes to github
- Export the contents at the HEAD of your ‘master’ branch in git to the trunk of your SVN repository.
- Commit the changes to SVN and therefore push them back to wordpress.org
- Create an SVN tag for wordpress.org to use and commit it (this will be the same value as Stable Tag: <tagnumber> in your readme.txt)
- Update the version number for future reference.
Hopefully this should make life a little easier for those WordPress plugin developers who wish to manage their projects in GIT
Download the script here