标题:
实例GIT的使用
[打印本页]
作者:
xueren
时间:
2013-8-11 23:49
标题:
实例GIT的使用
以最近编译android中使用到的例子记录一下GIT的使用
1,开始git服务
git daemon --verbose --enable=receive-pack --export-all --base-path=/opt/git-srv /opt/git-srv
其中--enable=receive-pack为允许提交到此开放的仓库中
2,完整克隆远程仓库到本地,包括所有LOG和所有分支
git clone --bare URL
如:
git clone --bare git://127.0.0.1/android/tools/repo.git
3,克隆某分支(默认为主分)到本地并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,查看分支
查看当前工作所在分支
$ git branch
* master
查看所有库的分支,包括本地与远程
$ 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
查看远程库的分支
$ 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,从当前现有分支中派生出新分支并工作到新分支中
git checkout -b NEW_BRANCH OLD_BRANCH
如:
从远程仓库的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,在当前工作分支中派生出新分支
git branch NEW_BRANCH
如:
git checkout android-x86-1.6-new
8,列出远程库
$ 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,删除/添加远程库
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,同步远程库的变动到本地
git remote update
注:
还不明白此命令与git fetch和git pull三者间的区别与关系
11,配置
git config
如,使用vi来编辑提交信息:
git config core.editor vi
12,本地库的改动同步到远程库
git push [--all]
13,其实一些常用的命令
git add //添加文件/目录
git rm //删除文件/目录
git diff //对比
git log //查看日志
git show
git commit -a [-m "xxxx"] //提交
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1