免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 892 | 回复: 0
打印 上一主题 下一主题

使用 git 管理源代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-12 17:27 |只看该作者 |倒序浏览

                               
git 参考文档:
     
git manual
     
http://toolmantim.com/articles/setting_up_a_new_remote_git_repository
常用的 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
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/52480/showart_1898662.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP