標(biāo)題: 實(shí)例GIT的使用 [打印本頁(yè)]

作者: xueren    時(shí)間: 2013-8-11 23:49
標(biāo)題: 實(shí)例GIT的使用
                                                                                                以最近編譯android中使用到的例子記錄一下GIT的使用

1,開始git服務(wù)
git daemon --verbose --enable=receive-pack --export-all --base-path=/opt/git-srv /opt/git-srv
其中--enable=receive-pack為允許提交到此開放的倉(cāng)庫(kù)中

2,完整克隆遠(yuǎn)程倉(cāng)庫(kù)到本地,包括所有LOG和所有分支
git clone --bare URL
如:
git clone --bare git://127.0.0.1/android/tools/repo.git

3,克隆某分支(默認(rèn)為主分)到本地并checkout
git clone -b BRANCH URL
如:
取得主分支
git clone git://127.0.0.1/android-x86/platform/manifest.git
取得android-x86-1.6的分支
git clone -b android-x86-1.6 git://127.0.0.1/android-x86/platform/manifest.git

4,查看分支
查看當(dāng)前工作所在分支
$ git branch
* master

查看所有庫(kù)的分支,包括本地與遠(yuǎn)程
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-x86-1.6
  remotes/origin/android-x86-v0.9
  remotes/origin/donut-x86
  remotes/origin/master
  remotes/origin/mirror

查看遠(yuǎn)程庫(kù)的分支
$ git branch -r
  origin/HEAD -> origin/master
  origin/android-x86-1.6
  origin/android-x86-v0.9
  origin/donut-x86
  origin/master
  origin/mirror
­
5,從當(dāng)前現(xiàn)有分支中派生出新分支并工作到新分支中­
git checkout -b NEW_BRANCH OLD_BRANCH­
如:­
從遠(yuǎn)程倉(cāng)庫(kù)的android-x86-1.6分支建立新分支android-x86-1.6-local­
$ git checkout -b android-x86-1.6-local origin/android-x86-1.6­
Branch android-x86-1.6-local set up to track remote branch android-x86-1.6 from origin.­
Switched to a new branch 'android-x86-1.6-local'­
­
6,切換工作分支­
git checkout BRANCH­
如:­
切到主分支­
$ git checkout master­
Switched to branch 'master'­
­
7,在當(dāng)前工作分支中派生出新分支­
git branch NEW_BRANCH­
如:­
git checkout android-x86-1.6-new­
­
8,列出遠(yuǎn)程庫(kù)­
$ git remote -v­
origin  git://127.0.0.1/android-x86/platform/manifest.git (fetch)­
origin  git://127.0.0.1/android-x86/platform/manifest.git (push)­
­
9,刪除/添加遠(yuǎn)程庫(kù)­
git remote rm NAME­
git remote add [--mirror] NAME URL­
如:­
刪除­
git remote rm origin­
添加­
git remote add --mirror git://git.android-x86.org/platform/manifest.git­
­
10,同步遠(yuǎn)程庫(kù)的變動(dòng)到本地­
git remote update­
注:­
還不明白此命令與git fetch和git pull三者間的區(qū)別與關(guān)系­
­
11,配置­
git config­
如,使用vi來(lái)編輯提交信息:­
git config core.editor vi­
­
12,本地庫(kù)的改動(dòng)同步到遠(yuǎn)程庫(kù)­
git push [--all]­
­
13,其實(shí)一些常用的命令­
git add  //添加文件/目錄­
git rm   //刪除文件/目錄­
git diff //對(duì)比­
git log  //查看日志­
git show­
git commit -a [-m "xxxx"] //提交­
                                                                                            







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1