get on with git
TRANSCRIPT
habeeb rahman | [email protected] | [email protected]
Get on with Git
topics
git waybasic commands
git way
direct acyclic graph
sha-1 hash
git objects: blob tree commit tag
sha-1 & blob
(master) $ echo -e 'blob 14\0Hello, World!' | shasum8ab686eafeb1f44702738c8b0f24f2567c36da6d
(master) $ echo 'Hello, World!' | git hash-object -w --stdin8ab686eafeb1f44702738c8b0f24f2567c36da6d
(master) $ ls .git/objects/8ab686eafeb1f44702738c8b0f24f2567c36da6d
(master) $ git show 8ab686eafeb1f44702738c8b0f24f2567c36da6dHello, World!
sha-1 & blob
(master)$ git cat-file -p 8ab686eafeb1f44702738c8b0f24f2567c36da6dHello, World!
(master)$ git cat-file -t 8ab686eafeb1f44702738c8b0f24f2567c36da6dblob
sha-1 and tree
git cat-file -p master^{tree}
sha-1 and commit
(master)$ git showcommit 0184521b4bc88bbb67891ed740140147c9ce61cdAuthor: Habeeb Rahman <[email protected]>Date:......
(master)$ git cat-file -t 0184521b4bc88bbb67891ed740140147c9ce61cdcommit
behind the sceneworking directory
working directory git add
committed snapshotgit commit
index(stage)
Basic commands
first things first
let git know your name and email:
git config --global user.name "Your Name"git config --global user.email "[email protected]"
git init
Create an empty git repository or reinitialize an existing one
$ mkdir getonwithgit$ cd getonwithgit/$ git initInitialized empty Git repository in /Users/hrahman/test/getonwithgit/.git/
git add
(master)$ echo "Hello World" > hello.txt(master)$ git status# On branch master# Initial commit# Untracked files:# (use "git add <file>..." to include in what will be committed)# hello.txtnothing added to commit but untracked files present (use "git add" to track)(master)$ git add hello.txt(master)$ git status# On branch master# Initial commit# Changes to be committed:# (use "git rm --cached <file>..." to unstage)# new file: hello.txt
git commit
(master)$ git commit -m "first commit"[master (root-commit) 05e96c3] first commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hello.txt(master)$ git showcommit 05e96c39452126e9310e84203af72f141c37a493Author: Habeeb Rahman <[email protected]>Date: Tue Jun 18 13:46:35 2013 +0530 first commitdiff --git a/hello.txt b/hello.txtnew file mode 100644index 0000000..557db03--- /dev/null+++ b/hello.txt@@ -0,0 +1 @@+Hello World
git diff
git diff: Show differences between your working directory and the index.
git diff –cached: Show differences between the index and the
most recent commit. git diff HEAD: Show the differences between your working
directory and the most recent commit.
git commit --amend
you commit and then realize you forgot to stage the changes in a file you wanted to add to this commit:$ git commit -m 'initial commit'$ git add forgotten_file$ git commit --amend
branch
create a new branch:(master)$ git checkout -b dev_featureSwitched to a new branch 'dev_feature'
switch to an existing branch:(dev_feature)$ git checkout masterSwitched to branch 'master'(dev_feature)$ echo "new feature" > feature.txt(dev_feature)$ git add feature.txt(dev_feature)$ git commit -m "feature"
branch
delete a branch$git branch -d dev_new_branch
show all local branches:$git branch
show all local and remote branches:$git branch -a
branch & merge
mergemerge 'dev_feature' branch into 'master':(dev_feature)$ git checkout masterSwitched to branch 'master'find out what's going to be merged:(master)$ git diff master...dev_featurediff --git a/feature.txt b/feature.txtnew file mode 100644index 0000000..2c61ec4--- /dev/null+++ b/feature.txt@@ -0,0 +1 @@+new feature added(master)$ git merge dev_featureUpdating 05e96c3..70c1e30Fast-forward feature.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 feature.txt
git blame
(master)$ git blame feature.txt70c1e306 (Habeeb Rahman 2013-06-18 15:50:47 +0530 1) new feature added
git log
(master)$ git logcommit 70c1e3069a68877fca9680b045185288c5201a46Author: Habeeb Rahman <[email protected]>Date: Tue Jun 18 15:50:47 2013 +0530
featurecommit 05e96c39452126e9310e84203af72f141c37a493Author: Habeeb Rahman <[email protected]>Date: Tue Jun 18 13:46:35 2013 +0530
first commit
(master)$ git log --oneline70c1e30 feature05e96c3 first commit
git grep
(master)$ git grep hellohello.txt:hello worldnew.txt:hello everyone
git clone
Local:git clone /path/to/repositoryRemote:git clone git://github.com/sample/test.git
git help
display help information about git$ git help help$ git help grep$ git help reset
further reading
http://git-scm.com/bookhttp://think-like-a-git.net/http://ftp.newartisans.com/pub/git.from.bottom.up.pdf