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


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


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


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: (more…)

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).


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.