Posted by
Neil – January 25, 2010
Not many people know this, but if you work for a draconian empire who insists on using Subversion across the board and won’t let you move to something a little better like Git, then there’s actually a tool just for this task.
Built into Git is git-svn:
TO WORK WITH AN SVN REPOSITORY BUT WORK WITH GIT LOCALLY:
git svn clone [http location of an svn repository]
Now you can work with the checked out directory as though it was a git repository.
TO PUSH (COMMIT) CHANGES TO THE REMOTE SERVER
git svn dcommit
TO UPDATE YOUR LOCAL REPOSITORY FROM THE SVN REPOSITORY
git svn rebase
NOTE: make sure you have your perl bindings to your local svn installation.
I screwed up, how do I reset my checkout?
git checkout -f
* Note, I don’t work for a draconian empire, and I use Git.
Posted by
Neil – January 14, 2010
Today, I came across the need for a function that would make most source control mechanism’s cry. Essentially I needed some work that was due to go into production in a few weeks, to go today, which meant I somehow had to grab some code that was deep down in my bleeding edge branch out into the limelight of the live server.
In Subversion, this would be pain, but luckily I’m using Git.
Out of the box, git comes with a very useful command cherry-pick. Essentially what this does is take one single commit, and then merges just those changes into the other branch. This is different to a regular merge in that it doesn’t pull ALL changes, so it’s much more precise.
git cherry-pick -n [The commit's SHA-1 Hash]
(Note that the -n option should be used when you don’t want Git to automatically commit the change into the new branch, but you should make sure your new commit message references the old commit for sanities sake).
Remember though, your newly merged into branch might not be working perfectly now, as you may now have unsatisfied dependencies, so test, test test!
Posted by
Neil – January 11, 2010
This is here more as a future note to myself, but hopefully someone out there will find this useful.
Essentially, imagine this: You have a remote repository (say, on GitHub), and that repo has many branches. You clone the repo and end up with the master branch in your local dev environment. Now what happens if you want to use one of the other branches in the repo?
Well, initially, you’d think you would create the branch locally, and pull the differences down:
git branch production
git checkout production
git pull origin production
but what if master is ahead of production (a likely scenario)? In this case this won’t work as your local production branch will now contain the changes in the master branch – as that’s where you originated production from on your machine.
What you need to do is:
git checkout -b <local_name_for_branch> <remote_source>/<remote_branch>
e.g
git checkout -b production origin/production
What this does is create a tracking branch. Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git push, Git automatically knows which server and branch to push to. Also, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch.