美文网首页
Git远程协作

Git远程协作

作者: shz_Minato | 来源:发表于2019-03-19 17:07 被阅读0次

Git远程协作

 基本流程

    A 将本地的commits推送至 远端
    B 从远端 拉取至 本地 
    B 修改拉取的commits,然后 推送至 远端

情景一:A 推送 B拉取

该场景下 A和B都没有 额外的操作

 A 将本地的commits 推送至 远端

    新建文件 echo ‘A add the fisrt line’ -> hello.txt
    
    将hello.txt提交并推送至 远端
    git add .
    git commit -m 'A add the first line'
    git push -u origin master
    

 B 将远端的commits 拉到 本地

    git pull <remote> <branch>
    remote:是远程的分支
    branch:要拉到的分支
    
    git pull包含了两步操作:
        第一:将远端的 commits 拉取到本地  fetch
        第二:将本地和拉取到的 合并 merge
        
    git pull origin master
    $ git pull origin master
      From 远端URL
      * branch            master     -> FETCH_HEAD  //mater 指向了 FETCH_HEAD  即 进行了merge
      //FETCH_HEAD 就是拉取到的HEAD

 B git log

Author: 
Date:   

    A add the first line  //这就是 远端的commit信息,

 流程图


image

情景二:B将修改的文件 push 至远端

    该场景下:
        B 首先了拉取了 文件,并对文件进行了 修改
        然后 将修改的commit信息 推送至远端

 B 修改hello.txt文件 并将文件 commit

    vi hello.txt
       B add the first line
    
    git commit -am 'B add the first line'
    

 B 将修改 推送至 远端

    git push -u origin master
    
    此时 git status
        $ git status
        On branch master
        Your branch is up-to-date with 'origin/master'. //本地分支和远端是一致的
        nothing to commit, working tree clean

 流程图


image

情景三:A将修改的文件 push 至远端

    此时远端已经比A多了一次提交
    

 A 修改hello.txt文件 并 提交

    vi hello.txt
        A add the second line
    
    git commit -am 'A add the second line'

 A push 自己的commit

$ git push
To 远程
 ! [rejected]        master -> master (fetch first) //拒绝 首先要 fetch
error: failed to push some refs to '' //错误:推送至远程失败
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

//由于远程包含了本地没有的工作,因此 推送失败。
//通常 是由于 别的仓库推送了 相同的 引用。
//你可能需要 合并 远程的 改变在 push 之前

//因此远端 比A本地 多了一次 提交  并且 改变的都是同一行 内容
//需要,处理这些相同的内容,在push之前 就需要 先pull一下。

git pull
    remote: Enumerating objects: 5, done.
    remote: Counting objects: 100% (5/5), done.
    remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    From 
        827ed67..2aaca86  master     -> origin/master //远程的版本信息已经 fetch下来
    Auto-merging hello.txt  //自动合并 hello.txt
    CONFLICT (content): Merge conflict in hello.txt //合并冲突  ----> 由于 修改的是同一行
    Automatic merge failed; fix conflicts and then commit the result. //需要解决冲突 merge失败
    
    
    vi 命令
        dd 删除行
        2,4d 删除2,3,4行
    
    冲突解决后
        git add hello.txt
        git commit
        git push

 流程分析


image

相关文章

  • git远程协作

    一般项目托管在github上,每个人完成功能后便提交到github。从远程仓库克隆数据时,git自动将本地mast...

  • Git远程协作

    Git远程协作  基本流程 情景一:A 推送 B拉取  A 将本地的commits 推送至 远端  B 将远端的c...

  • Git常用命令

    1.github简介:2.git远程协作的主要命令:git clone 获取一个远程仓库支持ssh,git,htt...

  • Git 系列文章

    GIT 初识 Git的基础操作 Git的远程操作 Git的分支管理 Git标签操作 Git团队协作 Git 多账户...

  • Git 基础 - 远程仓库的使用

    Git 基础 - 远程仓库的使用 远程仓库的使用 为了能在任意 Git 项目上协作,你需要知道如何管理自己的远程仓...

  • Git的分支管理与标签管理 (二)

    多人协作 利用git remote可以查看远程库的信息 $ git remote origin 也可以利用git...

  • git-远程仓库使用

    git远程仓库使用 官方文档 要参与任何一个 Git 项目的协作,必须要了解该如何管理远程仓库。远程仓库是指托管在...

  • Git命令

    多人协作时首先 git pull从远程拉下来代码进行开发,然后git add git commit -m "" g...

  • git

    git本地结构 git的代码托管中心 GitHub 码云 代码托管中心维护远程库 》团队内部协作 ...

  • 【学了就忘】GitHub — 68.GitHub介绍

    1、Git远程版本库概述 远程仓库是指托管在因特网或其他网络中的项目版本库。 为了能在任意Git项目上进行团队协作...

网友评论

      本文标题:Git远程协作

      本文链接:https://www.haomeiwen.com/subject/hcsnmqtx.html