Tech stuff about Cloud, DevOps, SysAdmin, Virtualization, SAN, Hardware, Scripting, Automation and Development

Browsing Posts tagged development

From time to time I get questions about how to check differences between two Git commits or two branches, I will answer those questions in this post.

How to check differences between two branches:

you have a dev branch and a master branch. You develop in the dev branch and would like to know if you were to merge the dev changes to master, what will those changes be:
Please note the order of the branch this states differences that will be added to master from dev.

How to check differences between two commits:

When you do git log you will see your different commits over time, you need to check the differences between two commits.

commit eab54d0ec21a1d7e351fee4c67139ada740e7e6b
Author: John
Date: Wed Jul 8 22:18:05 2015 -0400

Add feature 2

commit b722f1650b9fb33e0990beec027c097526c61478
Author: John
Date: Wed Jul 8 22:31:18 2015 -0400

Add feature 1

// Remember the order the first argument is the point in time, and the second item is what is added to the first argument’s commit

How to check differences between the HEAD (current state/latest revision) and a previous commit:

Or you can specify the last commit or a number of commits:

// Last commit

//Last 2 commits

How to check what changed since yesterday or a specific date:

// OR a specific date

How to check all changes to a specific file:

How to check size differences between two trees

I found this one in stackoverflow and has been very useful:

Reference Source:

“git cat-file -s will output the size in bytes of an object in git. git diff-tree can tell you the differences between one tree and another. Putting this together into a script called git-file-size-diff located somewhere on your PATH will give you the ability to call git file-size-diff . Putting this together we can try something like the following” – Stackoverflow

// Using it to check size differences between two branches:

// Using it to check size differences between the local master branch and the remote master branch, this is useful to know how much data will be downloaded when doing a ‘git pull’:

“Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.” –

In this guide I will walk you through setting up a Git server and accessing it from a Git client over SSH.

Git Server
I am using CentOS 5.3 as my server.
SSH Port: 22444 (As opposed to the default port 22, for increased security)

Install Git

yum install git

Create a folder where you will keep the repositories

mkdir /opt/git

Create a git user and change the owership and permissions of the previously created folder to the new user

useradd -c “Git Repository” git
chown git:git git:git /opt/git/
chmod 770 /opt/git

Create an empty project, I am calling my project ‘myproject’

mkdir /opt/git/myproject.git

Initialize the repository using –bare to only include objects at the server side

cd /opt/git/myproject.git
git –bare init

You are done with the Git server, let’s take a look at the client

Git Client
Install Git on your client.

sudo apt-get install git-core

Red Hat/Centos:
yum install git (I am using the rpmforge repo)

Now it’s time to version-control your project.

Create a new folder to put your code (unless it exists already)

mkdir /home/john/myproject

Now it is time to add your project to Git (locally):

cd /home/john/myproject
git init

Add all the files in the current directory to be source controlled:
git add *

Commit the changes:
git commit -m “Myproject first commit”

Tell the Git client where to find the server and remote repository

git remote add origin ssh://

Push your project to the server

If you have shared SSH keys:
git push origin master

OR If you dont have configured SSH keys:
git push ssh:// master

Now your project is under Git source control

Pull/Clone project:

The below will download the project folder in the current folder:

git clone ssh://

When you make changes to your project, you need to tell Git about it and commit the changes:

cd /home/john/myproject
git add *
git status (Check status)
git commit -a -m “A comment describing the change”