Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

[Git & Gerrit Home으로 돌아가기]

5. Training Set D

  • 0. Summary
  • 1.준비 - 원격 저장소를 준비하고, 첫번째 Working Directory를 준비
  • 2. Workdir1에서 branch 만들고 파일 생성 및 Commit
  • 3. Workdir2 master에서 파일 생성 , Commit ,Push
  • 4. Workdir1로 돌아와 branch merge하고 ,trying push, conflict
  • 5. Conflict at workdir1,  Pull , Resolve conflict, Push
  • 6. Pull at workdir2

0. Summary

  • 이번 Training Set은 실무에서 많이 나타날 수 있는 상황입니다.
  • 한 프로젝을 여러 명의 개발자가 서버에서 받아 각자 개발이 진행되는 경우, 서버에 Push할 때 Conflict이 날 수 있습니다.
  • 이 때는 Remote Repository에서 최신 내용을 fetch 받아와서 merge후 conflict을 해결해야, 서버에 Push할 수 있습니다.
  • 두 명의 개발자가 workdir1, workdir2 로 작업한다고 가정했을 때 conflict을 해결하고, 각자가 동일한 내용을 가지게 되는 상황을 가정해 보았습니다.
  • 차근 차근 따라해 보세요.
  • 전체 진행 시나리오는 다음과 같습니다.

...

  • [new branch] master -> master
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    nothing to commit, working tree clean


    4. Workdir1로 돌아와 branch merge하고 ,trying push, conflict

    $ cd ../workdir1
    $ git branch
  • branch2
    master
    $ git checkout master
    $ git merge branch2
    Updating 9418755..ce25c17
    Fast-forward
    branch2.txt | 1 +
    1 file changed, 1 insertion(plus)
    create mode 100644 branch2.txt
    $ git push origin master
    To file://c:/opt/repository/remote.git
    ! [rejected] master -> master (fetch first)
    error: failed to push some refs to 'file://c:/opt/repository/remote.git'
    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.

    5. Conflict at workdir1,  Pull , Resolve conflict, Push

    $ git fetch
    warning: no common commits
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From file://c:/opt/repository/remote
  • [new branch] master -> origin/master
    $ git status
    On branch master
    Your branch and 'origin/master' have diverged,
    and have 2 and 1 different commits each, respectively.
    (use "git pull" to merge the remote branch into yours)
    nothing to commit, working tree clean
    $ git pull
    fatal: refusing to merge unrelated histories
    $ git pull origin --allow-unrelated-histories
    Auto-merging branch2.txt
    CONFLICT (add/add): Merge conflict in branch2.txt
    Automatic merge failed; fix conflicts and then commit the result.
    $ vi branch2.txt : 충돌 해결
    $ cat branch2.txt : 충돌 해결 결과
    workdir1 br2 file created
    workdir2, master , file created
    $ git add branch2.txt
    $ git commit -m "master branch2.txt"
    $ git push origin master
    Counting objects: 9, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (6/6), done.
    Writing objects: 100% (9/9), 787 bytes | 0 bytes/s, done.
    Total 9 (delta 0), reused 0 (delta 0)
    To file://c:/opt/repository/remote.git
    90b8401..2f1dc1d master -> master
    $ git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    nothing to commit, working tree clean

    6. Pull at workdir2

    $ cd ../workdir2
    $ ls
    branch2.txt
    $ cat branch2.txt
    workdir2, master , file created
    $ git pull
    remote: Counting objects: 9, done.
    remote: Compressing objects: 100% (6/6), done.
    remote: Total 9 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (9/9), done.
    From file://c:/opt/repository/remote
    90b8401..2f1dc1d master -> origin/master
    Updating 90b8401..2f1dc1d
    Fast-forward
    branch2.txt | 1 +
    init.txt | 0
    2 files changed, 1 insertion(plus)
    create mode 100644 init.txt
    $ cat branch2.txt
    workdir1 br2 file created
    workdir2, master , file created