{:check ["true"], :rank ["log" "show" "look"]}
The general structure of a git repository is as follows:
0000 *
|
|
a0ef *--
| \ +----------------+
| \ | |
f13c * * ceff ======> | a filesystem |
| | | of files |
| | | |
89a0 * * d0d9 +----------------+
| /
| /
aa56 *--
master dev
In this section, we will be examine how to examine the timeline of a git
repository.
This will allow us to understand the evolution of the filesystem.
git log
is a versatile command to examine the timelines and commits of a repository.
Showing the history
\$ git log commit ca82a6dff817ec66f44342007202690a93763949 # The latest commit $t=2$ Author: Scott Chacon <schacon@gee-mail.com> # - author Date: Mon Mar 17 21:52:11 2008 -0700 # - timestamp # Change version number # - the commit message commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 # Previous commit $t=1$ Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008 -0700 Remove unnecessary test commit a11bef06a3f659402fe7563abf99ad00de2209e6 # The first commit $t=0$ Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 10:31:28 2008 -0700 Initial commit
- Commit names are hash codes that are automatically computed.
- Commits are listed in the reverse order, with the latest at the top.
Showing recent history with the git log -$n$
\$ git log -2 commit ca82a6dff817ec66f44342007202690a93763949 # The latest commit $t=2$ Author: Scott Chacon <schacon@gee-mail.com> # - author Date: Mon Mar 17 21:52:11 2008 -0700 # - timestamp # Change version number # - the commit message commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 # Previous commit $t=1$ Author: Scott Chacon <schacon@gee-mail.com> Date: Sat Mar 15 16:40:33 2008 -0700 Remove unnecessary test
Show history succinctly with the --pretty
flag.
\$ git log --pretty=oneline ca82a6dff817ec66f44342007202690a93763949 Change version number 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Remove unnecessary test a11bef06a3f659402fe7563abf99ad00de2209e6 Initial commit
- lists the commits with limited information
- other formats are
short
,full
, andfuller
.
Show history with custom format.
\$ git log --pretty=format:"%h - %an, %ar : %s" ca82a6d - Scott Chacon, 6 years ago : Change version number 085bb3b - Scott Chacon, 6 years ago : Remove unnecessary test a11bef0 - Scott Chacon, 6 years ago : Initial commit
More documentation available at: https://git-scm.com/docs/pretty-formats
Show timelines as a graph.
\$ git log --pretty=format:"%h %s" --graph * 2d3acf9 Ignore errors from SIGCHLD on trap * 5e3ee11 Merge branch 'master' of git://github.com/dustin/grit |\ | * 420eac9 Add method for getting the current branch * | 30e367c Timeout code and tests * | 5a09431 Add timeout protection to grit * | e1193f8 Support for heads with slashes in them |/ * d6016bc Require time for xmlschema * 11d191e Merge branch 'defunkt' into local
- The ASCII graph shows multiple branches with branches and merges.
- Remember the most recent commits are at the top.
git show
is a command used to show information of a given commit.
We will see how to use it to show:
Shows the full information of the HEAD
:
$ git show commit ca82a6dff817ec66f443 (HEAD -> master, origin/master, origin/HEAD) # Author: Scott Chacon <schacon@gmail.com> # Date: Mon Mar 17 21:52:11 2008 -0700 # commit information # changed the verison number # diff --git a/Rakefile b/Rakefile index a874b73..8f94139 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "simplegit" - s.version = "0.1.0" + s.version = "0.1.1" s.author = "Scott Chacon" s.email = "schacon@gmail.com" s.summary = "A simple gem for using Git in Ruby code."
We can specify a commit:
git show <commit>
Compact the commit information with --pretty=...
.
ca82a6dff817ec66f44342007202690a93763949 (HEAD -> master, origin/master, origin/HEAD) changed the verison number diff --git a/Rakefile b/Rakefile index a874b73..8f94139 100644 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "simplegit" - s.version = "0.1.0" + s.version = "0.1.1" s.author = "Scott Chacon" s.email = "schacon@gmail.com" s.summary = "A simple gem for using Git in Ruby code."
We can specify a commit:
git show --pretty=oneline <commit>
HEAD
HEAD^
HEAD^^
HEAD^^^
HEAD^$n$
git log
git ls-tree <commit>
git ls-tree --name-only <commit>
git show <commit>:<path>