git , 깃


  • 주요 명령어
    • 로컬관련
      • git init // ".git" 폴더가 만들어진다. git를 사용할 최소 상태가 되었다.
      • git add . //현재 폴더의 새로운,수정된 파일들은 Staging Area에 추가시킨다. (저장소에 저장된 상태는 아니다.)
      • git commit //저장소로 반영한다.
      • git status //현재 상태
      • git reset //작업 내용을 초기화할 때(잘 모르겠다. 좀더 알아보고 쓰자.)
        • git reset --soft HEAD^ //예제에 있던데 자세히는 모르겠다. Staging Area 내용이 되돌려진다.
        • git reset HEAD^ //자세히는 모르겠다. commit 한 내용이 되돌려진다.
      • git tag //현재의 태그 목록
        • git tag -l 'xxx*' //xxx로 시작하는 태그 목록
        • git tag -a v1.4 -m "comment" //Annotated tag : 기본적 태그
          • git tag -a v1.2 9fceb02 // 체크섬 시작이 9fceb02 인 부분에 태그를 붙인다.
        • 그외는 알아서 찾아서 써라... 디따 많네.
        • git show v1.4 // v1.4의 태그내용을 보여준다.
        • git push origin v1.4 // 태그공유 , 태그는 자동으로 공유되지 않는다. 버전되신 --tags로 여러개의 태그를 전송할 수 있다.
      • git branch //현재 브랜치 목록, 기본으로 master를 하나가 출력될것이다. (현재 브랜치는 *가 표시됨)
        • git branch [브랜치이름] //브랜치를 추가
        • git checkout [브랜치이름] //해당 브랜치로 변경, 로컬 파일 내용도 변경됨.
      • git merge [브랜치이름] //현재 브랜치에서 지정된 브랜치쪽의 파일을 merge한다.
        • 충돌난다면 문서를 수정 후 git add, git commit 해줘야한다.
    • Remote관련
      • git clone https://github.com/schacon/ticgit //리모트 저장소를 로컬위치에 복제한다.
        • origin이라는 별칭을 가지게된다.
        • SVN의 checkout과 비슷하다.
      • git remote add pb https://github.com/paulboone/ticgit // pb라는 별칭으로 리모트 저장소를 추가한다.
      • git remote -v //리모트 저장소 목럭
      • git push {remote} {branch} //리모드 저장소에 반영한다.
        • git push origin master
        • 여러사람이 동시 PUSH할 때는, 다음 사람은 merge 후 PUSH해야한다.
      • git checkout -b {local branch} {remote branch}
        • git checkout -b product_list origin/product_list
        • 리모트 브랜치를 로컬에 만들어준다.
      • git checkout -t {remote branch}
        • 리모트 브래치 이름을 기준으로 로컬에 브랜치를 만들어 준다.
          • -b 와의 차이점은 로컬 이름 수동 지정이냐? 자동 지정이냐? 차이
        • [pinspot@localhost public_html]$ git checkout -t origin/201606_coocha
          Branch 201606_coocha set up to track remote branch 201606_coocha from origin.
          Switched to a new branch '201606_coocha'
    • 파일 복구 / commit 취소 (참고 http://ecogeo.tistory.com/276 )
      • git reset
        • git reset HEAD <file> : unstage 상태로 되돌림
          • gir reset -- <file> : 상동
        • git reset HEAD^ : 최종 커밋 취소. 워킹 트리의 파일 보존
          • 파일은 수정된 내용이므로 add 해서 다시 커밋하면 됨.
        • git reset HEAD~2 : 최신의 2개의 커밋을 취소. 워킹 트리의 파일 보존
        • git reset --hard HEAD~2 : 최신의 2개의 커밋을 취소. 워킹 트리의 파일도 되돌림
        • git reset --hard HEAD : 현재 워킹트리 파일을 최신 커밋 내용으로 변경함
        • 옵션
          • --soft : 워킹트리 보존 , index보존
            • 즉, commit 전 add 상태가 됨.
          • --mixed : 워킹트리 보존 , index 취소 
          • --hard : 워킹트리 취소 , index 취소
          • HEAD : 최신 커밋 버전으로
          • HEAD^ :  최신 커밋을 취소
          • HEAD~1 : 1단계 취소. 
          • HEAD~2 : 2단계 취소.
        • git reset --hard origin/master
          • 워킹 폴더가 너무 이상하게 바뀌였고, 소스를 버려도 된다면.
            위 명령어로 마스터와 똑같이 맞춰버리도로고 할 수 있다.
      • git checkout (index와 commit에 영향없이)
        • git checkout <branch> : 워킹트리를 해당 브랜치의 내용으로 변경
        • git checkout master~2 <file> : 해당 브랜치 커밋 2단계 전에서 워킹트리 파일로 복구
        • git checkout <file> : index -> 워킹 트리
        • gir checkout -- '<filepattern>' : index -> 워킹 트리

  1. 사용 플로우
    1. 로컬에서
      1. git init
      2. 파일 추가 및 수정 및 삭제.
      3. git add .
      4. git commit
    2. 리모트에 반영
      1. git push {remote} {branch}
        1. 리모트와 다른 내역에 대해서 전부 반영함.



*. git 속에 다른 git을 추가할 때 


$ git submodule add https://github.com/mins01/ui_SelectArea.git SelectArea
Cloning into 'D:/work/mins01/html/WC2/etcmodule/SelectArea'...
remote: Enumerating objects: 81, done.
remote: Counting objects: 100% (81/81), done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 81 (delta 46), reused 53 (delta 29), pack-reused 0
Unpacking objects: 100% (81/81), done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.

*. 서브모듈 갱신

$ git submodule update --recursive --remote
이렇게 안하면 갱신을 안하는 경우가 많네....

서브모듈 갱신 초기화 (다른 곳에서 update 하는 경우)
$git submodule update --init --recursive

$ git submodule update  --remote --merge
이게 제일 잘 되는 듯. 모든 서브모듈 체크해서 리보드에서 업데이트하며 --merge 옵션으로 알아서 checkout 해준다.

*. git submilude 삭제 방법
http://snowdeer.github.io/git/2018/08/01/how-to-remove-git-submodule/
https://jjeong.tistory.com/1345

*. 로그에서 파일 목록 확인

git log --stat
=>
commit 17fad1cea78fb265f86d285e6cecf30ce3b3cc8e (HEAD -> master, origin/master, origin/HEAD)
Author: mins01 <mins01.lycos.co.kr@gmail.com>
Date:   Thu Mar 25 18:05:13 2021 +0900

    cli_xxx.php 적용

 application/config/constants_4_mh.php | 4 +++-
 application/config/database.php       | 2 +-
 application/controllers/ForCli.php    | 6 +++++-
 cli_dev.php                           | 3 +++
 cli_real.php                          | 3 +++
 5 files changed, 15 insertions(+), 3 deletions(-)


*. 로그에서 파일 목록 확인하기

# git log --name-only
=> 
commit c5fdbab2bbce9c4fa63239dda4e1109bdf5d1b89 (HEAD -> develop, origin/develop)
Author: mins01 <mins01.lycos.co.kr@gmail.com>
Date:   Wed Jun 2 16:42:27 2021 +0900

    테스트 소스 코드

app/Http/Controllers/TestTableApiController.php
app/Http/Controllers/TestTableWebController.php
app/Models/TestTable.php
database/migrations/2021_06_02_004823_test_table.php
database/migrations/2021_06_02_012145_test_table2.php

# git log --stat

commit c5fdbab2bbce9c4fa63239dda4e1109bdf5d1b89 (HEAD -> develop, origin/develop)
Author: mins01 <mins01.lycos.co.kr@gmail.com>
Date:   Wed Jun 2 16:42:27 2021 +0900

    테스트 소스 코드

 app/Http/Controllers/TestTableApiController.php    |  64 ++++++++
 app/Http/Controllers/TestTableWebController.php    | 180 +++++++++++++++++++++
 app/Models/TestTable.php                           |  20 +++
 .../migrations/2021_06_02_004823_test_table.php    |  37 +++++
 .../migrations/2021_06_02_012145_test_table2.php   |  38 +++++
 resources/views/testTable/create.blade.php         |  53 ++++++
 resources/views/testTable/edit.blade.php           |  54 +++++++
 resources/views/testTable/index.blade.php          |  42 +++++
 resources/views/testTable/show.blade.php           |  38 +++++
 resources/views/testTable/show2.blade.php          |  30 ++++
 routes/api.php                                     |   8 +
 routes/web.php                                     |  11 ++
 12 files changed, 575 insertions(+)


# git log --graph --all --decorate
(그래프,모든 브랜치, 브랜치 표시)

* commit bbbb184273a002eefbe856a710e6ae9da541a3f1 (HEAD -> main, origin/main, origin/HEAD)
| Author: 테스터 <test@tst.com>
| Date:   Sun Mar 6 21:28:18 2022 +0900
|
|     업로드쪽 계속 수정. 불필요 uploader deprecated 붙임
|
* commit c1e0b9f70321621fdcca438912c5c64f21c6b13a
| Author: 테스터 <test@tst.com>
| Date:   Sun Mar 6 20:29:43 2022 +0900
|
|     FileUploader 적용중
|
* commit b69a7ef765c6ec741e992d7de12707e89fabd699
| Author: test01 <test@tst.com>
| Date:   Thu Mar 3 18:06:11 2022 +0900
|
|     route_with_query $board->route_with_query  잡다
|
* commit db337c0826a41ec7d7005124c73d45010917cd0b
| Author: test01 <test@tst.com>
| Date:   Thu Mar 3 18:03:29 2022 +0900
|
|     loadTags 관련 수정
|
*   commit 968255f2fae0ddee0d316415b8d4ca3816486576
|\  Merge: b87d898 4c2f126
| | Author: 테스터 <test@tst.com>
| | Date:   Mon Feb 28 20:05:20 2022 +0900
| |
| |     Merge branch 'main' of https://github.com/test01/mhl into main
| |
| * commit 4c2f126ad5f8b5776f60416349630a3401bf896b
| | Author: test01 <test@tst.com>
| | Date:   Mon Feb 28 18:03:23 2022 +0900
| |
| |     잡다



*. 계정저장 삭제 (관리자 권한으로)
git config --system --unset credential.helper
git config --global --unset credential.helper

*. 계정저장 캐시 사용
git config --global credential.helper cache  //약 15분정도
git config --global credential.helper store //git 폴더에 저장
git config credential.helper store //git 폴더에 저장
git config --global credential.helper wincred  //OS 에서 제공하는 저장소 사용

*. git 인증정보 초기화
    댓글
    • No Nickname
      No Comment
    • 권한이 없습니다.
      {{m_row.m_nick}}
      -
    목록형 📷 갤러리형
    제목
    [기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
    유용한 리눅스(LINUX) 명령어
    [공지] 기술 게시판
    4.28
    4.29
    4.30
    5.1
    5.2
    5.3
    5.4
    5.5
    5.6
    5.7
    5.8
    5.9
    5.10
    5.11
    5.12
    5.13
    5.14
    5.15
    5.16
    5.17
    5.18
    5.19
    5.20
    5.21
    5.22
    5.23
    5.24
    5.25
    5.26
    5.27
    5.28
    5.29
    5.30
    5.31
    6.1