Share
Embed
Transcript
25 slides
-
git way direct acyclic graph sha-1 hash git objects: blob
tree commit tag -
sha-1 & blob (master) $ echo -e 'blob 14\0Hello, World!'
| shasum 8ab686eafeb1f44702738c8b0f24f2567c36da6d (master) $ echo 'Hello, World!' | git hash-object -w --stdin 8ab686eafeb1f44702738c8b0f24f2567c36da6d (master) $ ls .git/objects/8a b686eafeb1f44702738c8b0f24f2567c36da6d (master) $ git show 8ab686eafeb1f44702738c8b0f24f2567c36da6d Hello, World! -
sha-1 & blob (master)$ git cat-file -p 8ab686eafeb1f44702738c8b0f24f2567c36da6d Hello, World!
(master)$ git cat-file -t 8ab686eafeb1f44702738c8b0f24f2567c36da6d blob -
sha-1 and commit (master)$ git show commit 0184521b4bc88bbb67891ed740140147c9ce61cd Author: Habeeb
Rahman <[email protected]> Date:...... (master)$ git cat-file -t 0184521b4bc88bbb67891ed740140147c9ce61cd commit -
behind the scene working directory working directory git add committed
snapshot git commit index (stage) -
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 init Initialized 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.txt nothing 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 show commit 05e96c39452126e9310e84203af72f141c37a493 Author: Habeeb Rahman <[email protected]> Date: Tue Jun 18 13:46:35 2013 +0530 first commit diff --git a/hello.txt b/hello.txt new file mode 100644 index 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_feature
Switched to a new branch 'dev_feature' switch to an existing branch: (dev_feature)$ git checkout master Switched 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 -
merge merge 'dev_feature' branch into 'master': (dev_feature)$ git checkout master
Switched to branch 'master' find out what's going to be merged: (master)$ git diff master...dev_feature diff --git a/feature.txt b/feature.txt new file mode 100644 index 0000000..2c61ec4 --- /dev/null +++ b/feature.txt @@ -0,0 +1 @@ +new feature added (master)$ git merge dev_feature Updating 05e96c3..70c1e30 Fast-forward feature.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 feature.txt -
git blame (master)$ git blame feature.txt 70c1e306 (Habeeb Rahman 2013-06-18
15:50:47 +0530 1) new feature added -
git log (master)$ git log commit 70c1e3069a68877fca9680b045185288c5201a46 Author: Habeeb Rahman
<[email protected]> Date: Tue Jun 18 15:50:47 2013 +0530 feature commit 05e96c39452126e9310e84203af72f141c37a493 Author: Habeeb Rahman <[email protected]> Date: Tue Jun 18 13:46:35 2013 +0530 first commit (master)$ git log --oneline 70c1e30 feature 05e96c3 first commit -
git help display help information about git $ git help
help $ git help grep $ git help reset