Category Archives: Git

Git: Viewing Commits

If you want to see a history of commits you must use the following command:

$git log

The history will show the Commit Identification Number, Author, Date, and the commit message that was entered by the developer.

commit f78250ca8f938a6a427e37b6b8aedc8cc1a59c22
Author: David Loo
Date:   Sun Sep 16 21:21:50 2012 +0800

hello

commit dbf4aa15c50ccaec3a075399e336c0c49934122a
Author: David Loo
Date:   Sun Sep 16 21:20:51 2012 +0800

Hello

commit a204716d55aad334e5fc669fa1f9d611012461cb
Author: David Loo
Date:   Sun Sep 16 21:00:11 2012 +0800

Insertion

commit 2aaa14f6d89d75156db8f9a08a903ad83d471f92
Author: David Loo
Date:   Sun Sep 16 20:57:12 2012 +0800

If you want to view the individual commits that are listed above you can use the show command followed by the commit identification number: Continue reading

Git: Committing Changes

In Git when new content is added or modified, it needs to be committed as the latest version in the repository. To commit any changes open a terminal and from the command prompt enter the following command:

$cd HelloWorld
$echo "Made some changes" >> index.html
$git commit index.html -m "Made some changes"

The above commands will make a change to an existing file called index.html, and then commit the change with a log message.

If you have several changes and you commit all this changes, you can perform the following command:

$git add .
$git commit -m "Made some changes"

The above command performs a batch add and commit with a single log message. These commands can be entered in single line by specifying an add -a swith along with the commit command:

$git commit -a -m "Made some changes"

When the content is committed and just right after the command was entered, it will show the number of files and insertions (changes).

Reference:

Git: Adding Files to the Respository

Assuming that you have a created a respository by cloning or initialisation and you want to add content to the repository. Open a terminal and from the command prompt enter the following command:

$cd HelloWorld
$echo "Hello, World" > index.html
$git add index.html

First go into your working folder where the repository has been initialised, and create an index.html file with a text “Hello, World!” and then give the command git add to add the index.html file.

Please note when adding files to the repository it will not affect the latest version until you give it the commit command, I will discuss the commit command in my next post.

Next if you wish to add multiple files at the same time you can do the following:

$git add .

The dot or period “.” means all files that hasn’t been added to the repository.

Reference:

Git: Initialise a Repository on an Existing Folder

To create a repository from an existing folder you need to enter the following command in your terminal:

$mkdir HelloWorld
$cd HelloWorld
$git init

First command is to create a new folder called HelloWorld, then change directory to HelloWorld. Now inside the HelloWorld folder we enter the command git init to initial the repository.

After the repository have been initialised Git will place all the revision information into a hidden folder called .git, so now we have a new local repository.

Reference:

Git: Cloning a Repository

 

 

Git is an awesome source control, there are two sites that allow you to host repositories like GitHub and BitBucket. If you are looking for a free private repository hosting I would recommend BitBucket. 

Anyways let’s get started with cloning a repository on to your computer. First you will need some tools, if you are a windows user I would recommend you to get msysgit, and for Linux and Mac you can follow the download instruction from git-scm.com

I am going to use an existing public repository from GitHub called MonoGame, it’s a cross platform XNA development library for Mono. So open your terminal and enter the following commands:

$mkdir projects
$cd projects
$git clone https://github.com/mono/MonoGame.git

After the cloning has finish perform a ls -al command in your projects folder and you will see a MonoGame folder created with copies of the source code. Now you have cloned your first Git repository!