git 관리

  1. pull / fetch

    1. fetch: 원격저장소의 데이터를 Local에 가져오기만 하는 것입니다. 단순히 원격 저장소의 내용을 확인만 하고 Local Data와 병합은 하고 싶지 않은 경우 fetch 사용합니다.

      Untitled

      Untitled

    2. pull: 원격저장소의 내용을 가져와 자동으로 병합 작업을 실행(merge + fetch)합니다.

      Untitled

  2. commit + 되돌리기

    2-1. commit 이전 단계

    add: local에서 올리기 위해 올릴 파일들을 리스트업 하는 작업입니다.

    Untitled

    2-2. commit 시행 단계

    commit: add된 파일들을 local repository에 변경 작업하는 것이며 메시지 추가가 가능합니다.

    Untitled

    Untitled

    2-3. 잘못된 commit message 수정

    Untitled

    2-4. 잘못된 commit 수정

    2-4-1. git reset –[option] HEAD^ 또는 git reset –[option] <commit번호>

    Untitled

    Untitled

    Untitled

    Option List

    2-4-2. git reset HEAD^ = git reset HEAD~1

    2-4-3. git reset <commit번호 6자리> --[option] (commit상태를 지정해 reset)

    Untitled

    Untitled

    option: 2-4-1 참고

    2-4-4. reset / revert

    reset: 취소하려는 commit 자체를 commit log에서 제외합니다.

    git reset <이전 commit 번호 6자리> (<이전 commit 번호 6자리>로 리셋(삭제))

    Untitled

    revert: commit 변경 사항을 되돌렸다는 새로운 commit을 commit log에 생성합니다.

    git revert <현재 commit 번호 6자리>

    (<현재 commit 번호 6자리>에서 이전으로 되돌아 가기(생성 덮어쓰기))

    Untitled

    Untitled

    Untitled

    Untitled

    Untitled

    revert 선호 이유: 협업 상황에 있어 개인의 실수로 reset을 하면 다른 사람의 repository와 commit log가 일치하지 않게 되어버리기 때문에 commit log의 통일성을 위해 사용합니다.

  3. push + 되돌리기

    3-1. push 이전 단계

    2-1 단계 -> 2-2 단계를 시행합니다.

    3-2. push 시행 단계

    Untitled

    Option 참고: Git - git-push Documentation (git-scm.com)

    3-3. 잘못된 push 수정

    3-3-1. 원하는 시점으로 commit을 되돌리기(git reset)

    3-3-2. 되돌려진 상태에서 다시 commit(git commit)

    3-3-3. 원격저장소에 강제로 push(git push -f <remote name> <branch name>)

  4. Pull-Request(PR)

    Pull-Request: 기능 개발을 끝내고 master에 바로 merge하는 것이 아니라, branch를 중앙 원격 저장소에 올리고 master에게 merge해달라고 요청하는 것입니다.

    sub-branch 과정

    1. 내 원격 repository에 fork

      fork: 다른 사람의 저장소에 있는 repository를 내 원격 저장소, GitHub에 가져오는 것

    2. clone 설정

      clone: repository를 local저장소에 복사하는 것

    3. remote 설정

    4. branch 생성

    5. 코드 수정 작업 후 add, commit, push 실시(만약 나뿐만 아니라 다른 팀원이 소스를 수정했다면 fetch로 코드를 가져와 충돌을 해결한 다음 나머지 과정 실시)

    6. Pull Request 생성

      6-1. GitHub페이지에서 ‘Pull Request버튼을 이용하면, 어떤 branch를 제출할지 정할 수 있습니다.

      6-2. 기능 구현한 branch를 프로젝트 중앙 원격 저장소의 master branch에 병합 요청을 합니다.

    master branch 과정

    1. Merge Pull Request
    2. Merge 이후 동기화 및 branch 삭제

Issue

Ref

1번 에러

git add 취소하기, git commit 취소하기, git push 취소하기