2011年8月23日 星期二

Git讀書心得及進度

study status update
Pragmatic Version Control Using Git
Git權威指南(短期目標為 第一篇 初識GIT 及第二篇 GIT獨奏,即1-14章)



1.create
prompt> mkdir mysite
prompt> cd mysite
prompt> git init

prompt> git init mysite
Bear: 好像要比較新的版本才支援這個寫法

2.add into git
Add a New File or Stage an Existing File and Commit
2.1. add all files into git
prompt> git add .

prompt> git add -A
2.2. add single file into git
prompt> git add test.txt
Bear: add的用法除了用於把目標物加入版本庫之外,也用於commit前把目標物加入本次更新項目中。

Stage a Partial File
Note: [ ... ] indicates optional parameters.
prompt> git add -p [some file="" [some file="" [and so on]]]
... select hunks to commit ...

Add Files via Git’s Interactive Add Mode
prompt> git add -i

Stage Changes to Modified, Tracked Files
prompt> git add -u [ []]

3.commit it into local
Commit Changes to All Modified, Tracked Files
prompt> git commit -m "some message=''" -a
prompt> git commit -m "修改備註message,一定要填,別妄想不加-m能混過去"

--------------------------------------------

Revert Changes in a Working Tree
prompt> git checkout HEAD some file="" [some file=""]

Reset Staged Changes That Haven’t Been Committed
prompt> git reset HEAD []
Fix the Last Commit
... make whatever changes and stage them ...
prompt> git commit -m "" --amend
Amend the Previous Commit and Reuse a Commit Message
prompt> git commit -C HEAD --amend


Show Local Branches
prompt> git branch
Show Just Remote Branches
prompt> git branch -r
Show All Local and Remote Branches
prompt> git branch -a
Create a New Branch from the Current Branch
prompt> git branch
Check Out Another Branch
prompt> git checkout
Create a New Branch from the Current Branch and Check It Out
prompt> git checkout -b
Create a Branch from Another Starting Point
You can create a branch from any start point within the history of the
repository. The start point can be another branch, a commit name, or
a tag.
prompt> git branch
Overwrite the Existing Branch with a New Branch
prompt> git branch -f []
Move or Rename a Branch
...only if does not exist
prompt> git checkout -m
...overwriting any existing branch
prompt> git checkout -M
Merge Another Branch into the Current Branch
prompt> git merge
Merge but Don’t Commit
prompt> git merge --no-commit
Cherry-Pick Commit
prompt> git cherry-pick
Cherry-Pick, but Don’t Commit
prompt> git cherry-pick -n
Squash One Branch’s History into Another
prompt> git merge --squash
Delete a Branch
...only if branch has been merged into current branch
prompt> git branch -d
..even if branch has not been merged into current branch
prompt> git branch -D

Show All History
prompt> git log
Display Log with Patch Showing Change
prompt> git log -p
Limit Log to Show One Entry
prompt> git log -1
Limit Log to Show Twenty Entries and Patches
prompt> git log -20 -p
Show Commits from Past Six Hours
prompt> git log --since="6 hours"
Show Commits Older Than Two Days
prompt> git log --before="2 days"
Show Log for Single Commit Three Commits Prior to HEAD
prompt> git log -1 HEAD~3
Or...
prompt> git log -1 HEAD^^^
Or...
prompt> git log -1 HEAD~1^^
Show Commits Between Two Points
and in the following example can be a commit,
branch, or tag name. You can also mix different names.
prompt> git log ...
Show Log History as One-Liners
prompt> git log --pretty=oneline
Show Stats of Affected Lines for Each Line Entry
prompt> git log --stat
Show Status of Files Touched by a Commit
prompt> git log --name-status
Show the Differences Between the Current Working Tree and the
Index
prompt> git diff
Show the Differences Between the Index and the Repository
prompt> git diff --cached
Show the Differences Between the Working Tree and the
Repository
prompt> git diff HEAD
Show the Differences Between the Working Tree and the Previous
Point in Repository
can be a commit, branch, or tag name.
prompt> git diff
Show the Differences Between Two Points in a Repository
prompt> git diff
Show Stats from Differences
prompt> git diff --stat []
Annotate a File with Commit Information
prompt> git blame
Annotate File and Show Copy and Paste and Line Movement
Within File
prompt> git blame -M
Annotate File, Show Line Movement and Original File
prompt> git blame -C -C
Show Copy and Paste Within the Log
prompt> git log -C -C -p -1

git status

git diff

tag, rebase,