- 論壇徽章:
- 0
|
Product DetailsPaperback: 328 pagesPublisher: O'Reilly Media; 1 edition (June 4, 2009)Language: EnglishISBN-10: 0596520123ISBN-13: 978-0596520120
3.Getting Started
$ git$ git --version$ git commit --amend //修訂上一次提交的msg$ git help subcommand$ git subcommand --help
$ git commit -m "Fixed a typo." = $ git commit --message="Fixed a typo."
$ git checkout main.c //檢出為main.c的標(biāo)簽$ git checkout -- main.c //檢出名為main.c的文件
Quick Introduction to Using Git $ git init /在.git目錄下創(chuàng)建一個(gè)空的 Git 版本庫$ git add $ git commit$ git status
$ git config user.name "Jon Loeliger" //配置提交者名稱$ git config user.email "jdl@example.com" //配置提交者郵件地址
$ git log //git 日志
$ git show //查看最近一次詳細(xì)的提交信息 $ git show 97d65812a53b386831b41fc949ba80ef00b3cdf6 //查看指定提交的詳細(xì)信息
$ git show-branch //查看版本庫的當(dāng)前分支$ git show-branch --more=10$ git git-diff //比較當(dāng)前的工作目錄和版本庫數(shù)據(jù)庫中的差異
$ git rm filename //在版本庫中刪除一個(gè)文件$ git mv filename1 filename2 //在版本庫中重命名一個(gè)文件
$ git clone //復(fù)制一個(gè)版本庫
相關(guān)配置文件.git/config~/.gitconfig/etc/gitconfig
$ git config --global user.name "Jon Loeliger" ==>~/.gitconfig$ git config --global user.email "jdl@example.com" ==>~/.gitconfig
$ git config -l
$ git config --unset --global user.email //刪除一個(gè)設(shè)定
4.Basic Git Concepts blob對象,即文件.注意只包含內(nèi)容,沒有名字,權(quán)限等屬性(但包含大。 tree對象,相當(dāng)于文件夾。所包含的文件(blob對象)/文件夾(tree對象)的名字及其基本屬性(比如權(quán)限、是否符號鏈接等)的列表。 commit對象,表示修改歷史. commit對象可以視為類似矢量的概念, 由父commit(可能不只一個(gè),合并情形下)指向新的tree對象.子commit的直接父commit,使用“子commit^n“來引用. tag對象. 可以指向blob, tree, commit并包含簽名,最常見的是指向commit的PGP簽名的標(biāo)簽. blob, tree, commit 都是用其存儲(chǔ)內(nèi)容的 SHA-1 值命名的(不是簡單的對整個(gè)文件取 SHA-1 值),tag 自然使用的是普通名字.
文件存儲(chǔ) .git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad $ git cat-file -p 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
文件與目錄$ git ls-files -s //查看當(dāng)前的git庫中有那些文件$ git write-tree //將暫存區(qū)域的內(nèi)容寫到一個(gè) tree 對象$ git read-tree //將 tree 對象讀到暫存區(qū)域中去
5.File Management and the IndexTrackedIgnoredUntracked
$ git add$ git status$ git ls-files --stage$ git hash-object data$ git commit --all$ git rm filename$ git rm --cached filename$ git mv filename newfilename
.gitignore 文件
6.Commits$ git log master$ git show HEAD~2$ git show origin/master:filename
$ gitk
git bisect //在提交歷史中進(jìn)行二分查找$ git bisect good$ git bisect bad$ git bisect log$ git bisect reset
git blame 文件標(biāo)注$ git blame -L 12,22 filename$ git blame filename
7.Branches $ git merge-base original-branch new-branch
$ git branch new_branch //創(chuàng)建new_branch分支$ git checkout -b new_branch //創(chuàng)建并切換到new_branch分支$ git checkout new_branch //切換到new_branch分支$ git branch //列出當(dāng)前所有的分支
$ git show-branch //版本庫中分支狀態(tài)
$ git merge branch //將branch合并回當(dāng)前分支
$ git branch -d old_branch //刪除old_branch分支
8.Diffs $ git diff //比較當(dāng)前與暫存區(qū)域的差別
git diff commit //比較當(dāng)前與commit的差別git diff --cached //比較暫存區(qū)域與版本庫的差別git diff --cached commit //比較暫存區(qū)域與commit的差別git diff commit1 commit2 //比較commit1 與commit2的差別git diff --stat //對差異信息進(jìn)行統(tǒng)計(jì)
9.Merges$ git checkout branch$ git merge other_branch$ git mergetool //調(diào)用可視化的合并工具mergetool
10.Altering Commits git-reset --mixed 默認(rèn)選項(xiàng),重置暫存區(qū)狀態(tài)
--soft 將已經(jīng)提交的東西重新逆轉(zhuǎn)至“已更新但未提交(Updated but not Check in)的狀態(tài)
--hard 將工作樹中的內(nèi)容和頭索引都切換至指定的版本位置中,修改的內(nèi)容和git add的信息都會(huì)被丟棄
$ git cherry-pick commit //只合并指定的commit$ git revert commit //回滾代碼, 將內(nèi)容反向修改回去,版本會(huì)遞增,不影響之前提交的內(nèi)容
$ git commit --amend //修改最近一次commit的內(nèi)容,版本不變
$ git rebase //衍合(重新定義分叉點(diǎn))$ git rebase -i commit //修改最近一次commit的內(nèi)容,版本不變
11.Remote Repositories $ git push //遠(yuǎn)程提交$ git fetch //遠(yuǎn)程更新,僅獲取,不合并$ git pull //遠(yuǎn)程更新,獲取并合并
12.Repository Management
13.Patches
14.Hooks
16.Using Git with Subversion Repositories
Index
本文來自ChinaUnix博客,如果查看原文請點(diǎn):http://blog.chinaunix.net/u/1120/showart_2136540.html |
|