Wouldn’t it be nice to have a quick command you could run to visualize the commits on your local git repository that weren’t on the remote branch just prior to pushing them? Or perhaps to see what commits had been made remotely before pulling them down to your local copy and triggering a merge?
This brief how-to will explain just such a git log command, and how to setup the upstream tracking branch to enable the functionality required by the log command.
##First Iteration The first iteration of this command hard codes the remote branch name making it useful only if all your work is always on the same branch.
$ git log origin/master..HEAD --graph --pretty=format:'%Cred%h%Creset %d %s %Cgreen(%cr)%Creset %Cblue[%an]%Creset' --abbrev-commit --date=relative###Explanation
The ..HEAD portion of the command specifies a range for the log command to work against. In this case from current position on the master branch graph of the local repository to the HEAD position on origin copy of the master branch. By indicating the range with ..HEAD the log command will show those commits that exist on the local graph but not on the origin graph.
The rest of the command is just one way to condense and format the log command output. In this case we display an ASCII “railroad-style” graph of branchings, colorize the information displayed, abbreviate the commit message, and use relative dates.
As stated above, this command only works for branches called master. A better command would determine the name of the current branch and use it for the comparison.
##Second Iteration
git log @{u}..HEAD --graph --decorate --left-right --boundary --pretty=format:'%Cred%h%Creset %d %s %Cgreen(%cr)%Creset %Cblue[%an]%Creset' --abbrev-commit --date=relativeBy making use of the @{u} parameter the command now works regardless of the current branch. The suffix @{upstream} to a reference (short form @{u}) refers to the branch the reference is set to build on top of. A missing reference defaults to the current branch.
So this second command works for the current branch, regardless of what it is named. But it still only shows the local commit differences. Wouldn’t it be better to see both the local commits not yet on the remote and the remote commits not yet on the local?
##Third Iteration
The notation A..B means revisions in B that are not in A. Adding dot to the list, e.g., A...B means revisions in either A or B that are not in the merge bases for A and B. In other words, show the commits in either local or remote that aren’t in the other.
git log @{u}...HEAD --graph --decorate --left-right --boundary --pretty=format:'%Cred%h%Creset %d %s %Cgreen(%cr)%Creset %Cblue[%an]%Creset' --abbrev-commit --date=relativeNow with one quick command (I suggest creating a gitconfig alias) you can determine what the “commit difference” is between your local branch and it’s upstream copy.
##A Note About Upstream
In order for th @{u}..HEAD or @{u}...HEAD notation to work, your branch must have an upstream tracking branch defined. You can see what the upstream branch is by running this command, substituting the branch name as necessary:
$ git config branch.<branchname>.remoteIf the command returns nothing then you need to set the upstream branch. Run this command one time to establish an upstream tracking branch.
$ git push -u origin <branchname>The -u parameter indicates that we want to establish the origin version of as the upstream tracking branch for the local copy of . Remember that origin is just an alias that was created for a particular repository when the git remote add command was run.
##Conclusion
With an upstream tracking branch in place, using the @{u}...HEAD range specification on a git log command allows you to see the divergence (if any) your local copy has prior to running either a git pull or git push. By setting up and alias in your gitconfig file you can easily run git ahead anytime you want or need.
##References The following stackOverflow pages were instrumental in creating this how-to.
Substitute current git branch name into git log command
Git command to emit name of remote tracking branch
Difference in ‘git log origin/master’ vs ‘git log origin/master..’
When I first started exploring Sublime Text 2, I added what I thought were the necessary preference files and folders to my dotfiles repository. I’ve since come to understand that you only need to house one specific folder to effective version and share your personalized Sublime Text 2 configuration.
First make sure Sublime Text 2 is not running.
Next make a copy of ~/Library/Application Support/Sublime Text 2/Packages/User to the local copy of your dotfiles repository.
$ cp -r ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Users ~/.dotfilesSwitch to the original location of the Users directory, delete it, and then create a symlink to the copy in your dotfiles repository.
$ cd ~/Library/Application\ Support/Sublime\ Text
$ rm -rf Users
$ ln -s ~/.dotfiles/Users UsersStoring the Users directory in your dotfiles works only if you are using Package Control. Package Control keeps a list of your installed packages in a .sublime-settings file stored in User. When installing Sublime Text 2 on a new machine, you should first install Package Control and then link to your User directory in your local dotfiles repository. Package Controller will find the list of packages, see that it does not have them installed locally, and fetch them in the background (you can observe it working in your Sublime console).
Bonus Tip
If you manage to bork your Sublime Text install and want to nuke it from orbit to start over just remove your data folder. Depending on your operating system here is where the data folder can be found:
~/Library/Application Support/Sublime Text 2~/.config/sublime-text-2%APPDATA%\Sublime Text 2To return to a fresh-out-of the-box install:
This will wipe out all your preference settings and installed packages. Use as a last resort only.
{{ “0399158294” | amazon_mediumleft_image }} Shadow Patrol by Alex Berenson is the third book of the year for me. And the first I’ve read by this author. It centers around a former CIA agent on assignment in Afghanistan. Looking at the flyleaf of the book I discovered a whole series of books preceding it. This one was good enough that I expect to go back and read the ones preceding it to catch up.
This is a fascinating idea. By re-ordering the movies, and outright eliminating one, you get a more coherent and satisfying story. The next time I watch the Star Wars Saga I’ll be using machete order.
Tonight I managed to get 100% on the first quiz from the Coursera Calculus One course. As someone who was a mediocre student overall growing up, and specifically a poor mathematics student, this is huge.
In high school I barely scraped by in Algebra. The rules just never made sense to me. Geometry was different; I loved proofs and theorems. In college my major required that I take “Calculus for Business Majors”. I ended up taking the course twice in order to get a passing grade. It was Algebra all over again, only worse.
The part that stung about failing calculus was how stupid it made me feel. It seemed that no matter how hard I tried I just could not get the same answers as were in the book.
After successfully completing the Functional Programming Principles in Scala course last fall, I decided to try my hand at a new way of learning Calculus. What Coursera does is break the material down into smaller chunks. Each subtopic is captured in a short lecture video. You can watch the videos as many times as you want, pause, backup, re-watch. The material in the videos is presented in very engaging ways, and often reiterated multiple times. There are practice problems that come with step by step hints for when you get stuck. When you miss a problem the system presents you with more like it so you can learn. The quizzes can be taken (for this course) 100 times and your highest score will be used.
In short, the course is laid out in a manner that encourages you to learn, that helps you to learn. In school I often felt like I was being punished for not learning rather than being assisted when I failed. My experience this week with functions, domains, and limits in Calculus One has been refreshing and invigorating. I’m sure that there will be times of frustration in the weeks to come, but I feel like I will learn Calculus as a result of this course. Something I never thought I would be able to count among my accomplishments.
Kudos to Coursera.
Once upon a time you found a project on Github that caught your fancy and you made a fork of your very own. You made some changes and time passed. Now you realize that the original project has some new features you want in your fork. What to do?
##Step 1
Add a remote to the original, or upstream project.
$ git remote add upstream git://github.com/originalOwner/project.gitYou can confirm the remote with this command:
$ git remote -vThere will (at least) be a pair of references to origin (your fork of the project) and a pair of references to upstream, the new remote you’ve added for the upstream project.
##Step 2 Fetch all the changes from the upstream project. This will gather all the branches of that upstream project.
$ git fetch upstream##Step 3 Make sure you are on the master branch of your local repository:
$ git checkout master##Step 4 Rebase your branch so that any changes you’ve made which aren’t in the upstream repository are replayed, thus preventing you from losing them.
$ git rebase upstream/master##Step 5
Push your newly updated local repository to your Github fork. You may need to add the -f flag to force the push on the initial push after a rebase.
$ git push [-f] origin master
{{ “0451237900” | amazon_mediumleft_image }} Trust Your Eyes is the first book by Linwood Barclay I’ve ever read. It won’t be the last. Filled with plots twists and turns, including a startling revelation in the very last paragraph, I thoroughly enjoyed Trust Your Eyes.
I’ll be working my way through his eleven other books just a quickly as I can get them.
What happens when you plot a point for every person captured in the census? You get a map.
{{ “0451411080” | amazon_mediumleft_image }} Book one of 2013 is one I’ve had on my shelf for several years but never read. Starting with a large number of facts Christopher Hyde weaves a good story around a possible movie of the execution of the Romanov family. Sometimes truth is stranger than fiction, and when you can blur the lines between the two, you get a good espionage tale.
With the turn of a new year I was curious how many postings I made in the past 12 months, and how many words I had written on my sites.
Counting the number of postings is simple, it’s just the number of files in my _posts folder.
$ cd path/to/source/_posts
$ ls -l | grep 2012 | wc -lCounting the number of words contained in those files with a 2012 in the name was a bit trickier, but a couple of searches and two Stack Overflow answers combined gave me this:
$ cd path/to/source/_posts
$ find . -name "*2012*" -maxdepth 1 -print0 | xargs -0 cat | wc -wArmed with these two commands I decided it would be fun to see, year by year, the number of postings made and words written.
My Cello site is much younger, but here are the year by year statistics for it as well.
Combined, I’ve written 2,274 posts containing 693,865 words.