Skip to content

Iterate and navigate through history

bestapps edited this page Aug 25, 2012 · 6 revisions

Iterate and navigate through history.

  • Let's edit our README file, add a line to it.
  • And add a new file just for fun.
  • I call that new file .gitignore and put file patterns in it:
ben@GregoryHouse:~/tmp/testRepo (master *)$ cat .gitignore
*.swp
*.~
hiddenFile
ben@GregoryHouse:~/tmp/testRepo (master *)$ touch hiddenFile
ben@GregoryHouse:~/tmp/testRepo (master *)$ ls -la
total 32
drwxrwxr-x 3 ben ben  4096 Aug 23 07:22 .
drwxr-xr-x 4 ben ben  4096 Aug 23 07:04 ..
drwxrwxr-x 8 ben ben  4096 Aug 23 07:19 .git
-rw-rw-r-- 1 ben ben    21 Aug 23 07:21 .gitignore
-rw-rw-r-- 1 ben ben     0 Aug 23 07:22 hiddenFile
-rw-rw-r-- 1 ben ben   113 Aug 23 07:17 README
-rw-r--r-- 1 ben ben 12288 Aug 23 07:22 .README.swp
ben@GregoryHouse:~/tmp/testRepo (master *)$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   README
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.gitignore
#       .README.swp
#	hiddenFile
no changes added to commit (use "git add" and/or "git commit -a")
  • We add the changes
ben@GregoryHouse:~/tmp/testRepo (master *)$ git add .gitignore README
ben@GregoryHouse:~/tmp/testRepo (master +)$ git commit
[master c6c5566] Add .gitignore, add a line to README
 2 files changed, 5 insertions(+)
 create mode 100644 .gitignore
git status
# On branch master
nothing to commit (working directory clean)
  • However, we still have our hiddenFile and .README.swp there, so .gitignore hides them to git.
  • Let's have a look at all we have done so far:
ben@GregoryHouse:~/tmp/testRepo (master)$ git log
commit c6c55668158d872f39861a4620325f059938f452
Author: Benoît Bleuzé <benoit.bleuze@gmail.com>
Date:   Thu Aug 23 07:25:19 2012 +0200
    
    Add .gitignore, add a line to README
     
commit 4a9debafe19cd53dc9fb484c6df419c1e9344a6e
Author: Benoît Bleuzé <benoit.bleuze@gmail.com>
Date:   Thu Aug 23 07:15:01 2012 +0200
 
    First commit: add README
  • In a more dense way, showing only the first digits of the hash tags and the first line of the commit message per line:
ben@GregoryHouse:~/tmp/testRepo (master)$ git log --oneline
c6c5566 Add .gitignore, add a line to README
4a9deba First commit: add README
  • git log has many many options for finding the right commit. Having a look at git log --help may be a bit frightening though.

  • Here you could also try gitk or gitx or gitg for exploring the history. They are much more convenient than the logs. This will prove even more valuable during the branching part of the tutorial.

jump to Operations on Files

Clone this wiki locally