Git logs and commits across multiple branches

Like any good computer scientist I use git for many research and personal projects. My primary use of git is for code backups rather than collaborating with others. However, in some of my recent work I’ve been sharing repositories with colleagues and students which has caused me to improve my git skills.

The following is some of the functionality I’ve only recently discovered that has been extremely helpful:

git cherry-pick commit-id-number

This command proved very useful when I recently forked a github repo and made some changes to the source code for the specific project I’m working on. I soon discovered a bug in the original repository that a number of users had reported. I was able to fix the bug in my fork, but as my fork had changes that I didn’t want to contribute back to the original repository I was able to use the cherry-pick command to bring across only the specific commit related to the bug fix.

git checkout --theirs conflicted_file.php

Merge conflicts suck. But sometimes despite trying to pull as often as possible they still occur and can full your code with ugly messes to clean up. I recently wanted to throw away my changes to a file and simply use the latest committed file. By using git checkout –theirs I was able to throw away all my changes and go for the file that had been committed and conflicted with my changes. Conversely, you can use –ours to replace the conflicted file in favour of local changes.

git shortlog

During the past few weeks the students in the course I’ve been teaching this semester have used git to collaborate on group projects. The git shortlog command produces a list of commits grouped by each author allowing you to quickly see the relative rate at which people are contributing commits to a repository.

git branch -a

When you clone a remote repository it pulls in all branches from the remote repository. However, if you just type git branch you won’t see this. The -a flag allows you to see everything.

git log --all

The same issue applies when you are trying to see the log across all commits across all branches, just using the standard git log command will only produce the log for the current branch. The -all flag allows you to see the log across all branches, combining this with the cherry-pick command is very useful when you want to bring across just one set of changes rather than merging a whole branch.

git log --all --stat --author="Tom"

Bringing this all together I’ve begun to regularly use the above command to see all commits by a single user across all branches. This has been a good way to measure students’ contributions to a group project (note: the author option is case sensitive).

Central Europe Adventures 2016 – Part Eighteen: Aachen and Liege

Departing Osnabrück in the rain I had to catch two trains to get to Aachen. I had hoped to stop for a few hours in Dusseldorf but given the wet weather I stayed on the train to Cologne and then switched for the local train to Aachen. The second train I caught was completely full of football fans and I had to stand for close to half the journey.

Once I arrived in Aachen I walked down the road to my hotel, the Ibis Hauptbahnhof, which ironically is further from the main station than the Ibis Marschiertor. After I had checked in I met up with a friend who was so excited to see me she literally knock me to the ground when running up to give me a hug. We then joined a larger group of students and had Flammkuchen for dinner (it’s rather similar to Pizza) and rounded off the night drinking a bottle of wine in the student dorms at the university.

Continue reading

Photos: 20th Biennale of Sydney

Over the past two months I’ve spent a few weekends checking out the 20th Biennale of Sydney. I haven’t been to all the locations where the Biennale is held this year, but I have seen the exhibits at Cockatoo Island, the MCA and the NSW Art Gallery.

Many of this year’s exhibits are audio/visual in nature but the few photos below capture at least some of the amazing art that’s there to be experienced.

Central Europe Adventures 2016 – Part Seventeen: Osnabrück and Münster

After four nights in Berlin I caught the train across to Osnabrück where I have a good friend. Osnabrück is only three hours from Berlin but it felt like a very long way. About halfway through the journey I realised I had given my friend the wrong arrival time and he ended up waiting in the cold and damp of the station for an hour. Once we had dropped my bags at his place we headed out to a cafe for cake and a hot drink.

Continue reading

Economic and Historical Perspectives

A few weeks ago I finished reading a book called “Russia Which Way Paradise” written by former ABC Russia Correspondent Monica Attard. The book was written around 20 years ago and documents the collapse of the Soviet Union. It’s an interesting book to read given the current political situation in Russia and the relationship between Russia and the international community.

There is one story in the book that I found particularly humorous:

Natasha told me when I first arrived in Moscow that I was now living in the richest country in the world, a comment that struck me as rather odd given the sad-looking shop shelves, the run-down buildings and poorly dressed people I was seeing.
‘How can this be the richest country in the world?’ I asked her.
‘Well, as we say in Russia, people have been stealing for seventy years and there’s still something left to steal.’

Code Structure, Random Number Generation and Conditional Probability

I had an interesting discussion with a group of students this afternoon which highlighted how important it is to understand conditional probability and how code structure can produce unexpected results.

The students’ code contained three lists and a random number generator. The random number generator was meant to randomly chose which list to take something from with equal probability (that is 1/3 chance of selecting from each of the lists). However, somehow one of their lists was being selected far more than the others.

Their code looked similar to the following:

if (random.nextInt(3) == 0) {
  // select from list 1
} else if (random.nextInt(3) == 1) {
  // select from list 2
} else {
  // select from list 3
}

Can you spot the bug? Why would this not generate equal probabilities of selecting from each list?

I wrote some of my own code to test this code structure almost 100 million times:
int count0 = 0;
int count1 = 0;
int count2 = 0;

// loop almost 100 million times
for (int i = 0; i < 99999999; i++) {
  if (r.nextInt(3) == 0) {
    count0++;
  } else if (r.nextInt(3) == 1) {
    count1++;
  } else {
    count2++;
  }
}

Which generated the results:
Count0 = 33333271
Count1 = 22221788
Count2 = 44444940

Which demonstrates this code doesn’t generate equal probabilities.

The problem is the second random number generation:

if (r.nextInt(3) == 0) {
  count0++; // this has 1/3 probability (0.333333333333333)
} else if (r.nextInt(3) == 1) { // this else will run 2/3 of the time
                                // and resolve true 1/3 of the times it runs

  count1++; // 1/3 * 2/3 this line will run... i.e. 2/9 probability (0.22222222222)
} else {
  count2++; // 2/3 * 2/3 this line will run... i.e. 4/9 (0.4444444444444)
}

Restructuring the code to only generate the random number once and storing this in a temporary variable makes a huge difference:

int rInt = r.nextInt(3); // only generate a random number once.
if (rInt == 0) {
  count0++; // this will run 1/3 of the time.
} else if (rInt == 1) {
  count1++; // this will run 1/3 of the time.
} else {
  count2++; // this will run 1/3 of the time.
}

And the results of this are:
Count0 = 33333907
Count1 = 33332586
Count2 = 33333506

Which looks much better.

(Note: alternatively you could make the second random number generation be out of 2 rather than 3 but this would be slower as the random number generator will take a few CPU cycles to calculate.)

Central Europe Adventures 2016 – Part Sixteen: An Additional Day in Berlin

On the morning that I was due to leave Berlin I decided to stay an extra day. Although I had been in Berlin for three nights, I had only spent one afternoon in Berlin proper as I had been ill almost all the rest of my time there.

I began the day by meeting up with a friend who had studied in Sydney for a number of years. We went for a walk along the runway of Tempelhof Feld – an airport that has now been turned into parkland – and the surrounding suburbs.

Continue reading

Central Europe Adventures 2016 – Part Fifteen: Exploring Luther’s Wittenberg

I’ve wanted to travel to Wittenberg since traveling past it on my previous visit to Germany. I wanted to know how a man from such a small town could have such a large impact on world and church history and beliefs.

Although I was still not very well after coming down with food poisoning I took some medication and caught a train from Berlin to Wittenberg for the day trip.

I was immediately lost on arrival at Wittenberg train station as the train station is not in the centre of the town like I had expected it to be. To ensure that I was even more lost there was no signage or map at the station showing the way to the centre of town.

I decided that the best idea was to follow the three people in front of me along the road. This plan worked until we came to the first intersection where the three people all walked off in different directions.

At this point I found a street name that matched the small printed map of Wittenberg that I had and despite realising I was in the complete opposite end of the town to what I thought I was at least I knew that I was heading in the right direction (For the record: Lutherstadt Wittenberg and Lutherstadt Wittenberg Altstadt are two different train stations).

My first stop in Wittenberg was at the Lutherhaus museum. I spent almost two hours here as the museum has a great overview of all aspects of Luther’s life and relationships with his family, community and contemporaries.

Continue reading

Central Europe Adventures 2016 – Part Fourteen: Travel Drama and Sickness in Berlin

My visit to Berlin was filled with unneeded drama. Upon arrival from Dresden I decided to drop my bags at my hotel before spending the afternoon exploring Mitte. To get to my hotel I needed to catch an S-Bahn from Berlin’s Hauptbahnhof to Hackescher Markt. As I stepped off the escalator onto the S-Bahn platform I just missed a train, and then the next one pulled into the station so crush loaded that you couldn’t get a suitcase onboard. After waiting a very long time for a third train I made it to my hotel.

Once I had checked into my hotel I started to walk towards the Brandenburg Gate along Unter den Linton. As we walked along the road through the area around Museumsinsel we noticed many police vehicles, and we then found ourselves stuck between two road closures as the police were closing down the area for the visit of the Israeli Prime Minister. After being allowed to jump a barricade to get out of the exclusion zone we took a detour to the Berlin Konzerthaus where Ai Weiwei had wrapped the pillars of the building in life vests used by refugees to get to Europe. We then walked back to Unter den Linton and got to the Brandenburg Gate as the sun was setting.

Continue reading

Central Europe Adventures 2016 – Part Thirteen: Bundeswehr Military History Museum Dresden

The Militärhistorisches Museum der Bundeswehr (Bundeswehr Military History Museum) in Dresden contains a large number of military exhibits covering the modern history of Germany and has free admittance on Monday nights. I was fortunate enough to be visiting Dresden on a Monday, so after spending the day exploring Dresden’s old city and New Green Vault my friend and I caught a tram the few kilometers to the museum.

My primary motivation for visiting the museum (other than free entry) was to see the Soyuz Space Capsule and V-2 Rocket. When I arrived, I decided to follow the recommended path through the museum which takes you from the middle ages through to current German military deployments.

The quality of the exhibits and the tone of the museum is really good. Over the last 150 years, Germany has experienced many wars. By following the historical timeline through the museum you see both the advancement of technology but also the history of the modern state of Germany. The museum did well to not express a statement about the might of German technology nor did it have walls of remembrance like many military museums in Australia and New Zealand have. I was most impressed by how it handled the Second World War exhibits which included historical German propaganda and other political items, they were presented them in a simple, clear and factual manner.

Below are a few photos from my visit. Despite originally going to see the Soyuz capsule and V-2 I ended up becoming more engrossed in the Prussian and Cold-War era exhibits.