Chinaunix首页 | 论坛 | 博客
  • 博客访问: 581112
  • 博文数量: 126
  • 博客积分: 4379
  • 博客等级: 上校
  • 技术积分: 2110
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-06 22:35
文章分类

全部博文(126)

文章存档

2012年(5)

2011年(3)

2010年(2)

2009年(116)

分类: 嵌入式

2009-11-29 12:20:08

git 参考文档:
    
    

常用的 git 命令:
    
 * 如何创建 git repository
   * 服务器端
     # cd /export/git
     # mkdir git-sample.git
     # cd sample.git
     # git --bare init
     # git update-server-info

   * 用户端
     # mkdir git-sample
     # cd git-sample
     # copy your file to this direcotry
     # git init
     # echo "*.o" >> .gitignore    >>>> 编辑 .gitignore 文件
     # git add .
     # git commit -m "init"
     # git push SERVER_ADDRESS:/export/git/git-sample.git master

 * clone源代码:
    # git clone git+ssh://SERVER_ADDRESS/export/git/git-sample.git

 * commit 修改
    # git status
  # git add file1 file2 ...
    # git commit
    # git push

 * 更新源代码  
    # git pull

关于 git branch

  * git branch -a  列举所有branch
  * git branch -r   列举remote branch
  * git branch -l   列举local branch

     remote branch 保存在 .git/refs/remote/, 而local  branch保存在 .git/refs/heads/ .

  * 使用不同的 branch 来同时做不同的工作:
  例: branch master  ->  工作1
           branch work_a ->  工作2
 
   # git checkout -b work_b
     do you work_b here and then commit to server.
     # git push

     # git checkout master
     do you work_a here and then commit to server.
     # git push

     如果都完成了,需要合并的话:
     # git checkout master
     # git merge work_b
     # git push
     # git branch -d work_b    -> 删除branch

  * 从remote repository里更新源代码
    假设进行内核开发,当前工作是基于 2.6.29 版本的内核开发的。现在  v2.6.30 的内核出来了,希望将版本升级为最新的 v2.6.30.

     (Mainline kernel)    
          v2.6.29
           :    v2.6.30-rc1       v2.6.30
           :     :                 :
     o-----o-----o---...........---o  master
    
     (My kernel tree)

          v2.6.29
           :    v2.6.30-rc1       v2.6.30
           :     :                 :
     o-----o-----o---...........---o   master     (mainline)
           |                       |                              
           |                        \  (git pull)                         
           |                         o update     (my tree)
            \ v2.6.29-zeng           |
             o-----o-----o-----o     |  master     (my tree)
                   M1    M2    M3    |
                                      \ (git merge update)
                                       o-----o-----o-----o  master (my tree)
                                             M1    M2    M3
   可以用下面的步骤:
   # git checkout -b update v2.6.29     -> current branch is update
     # git pull git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

     # git checkout master
     # git merge update
     # git push
     # git branch -d update   -> delete this branch

* 在局域网中建立 git repository 镜像
   在局域网中,如果大家都需要访问(pull only) 外部git repository, 比如:  git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git, 这时候可以在局域网中建立一个镜像 git repository, 定期从外部更新。
  
   # mkdir linux-2.6.git
   # git --bare init
   # git update-server-info

   # mkdir linux-2.6
   # git init
   # git remote add -f -t master -m master origin git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
   # git merge origin
   # git push git+ssh://114.180.90.213/export/git/linux-2.6.git master
   
如果 merge(合并)过程中出现冲突(conflict), 需要恢复到合并之前的状态,使用:
   # git reset --hard HEAD
阅读(2046) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~