본문 바로가기
TIL

[TIL] chmod / Git 영역, 상태, commit, branch

by thegreatjy 2023. 9. 25.
728x90

chmod

chmod -R nnn filename

-R : recursive, 하위 디렉토리나 파일 모두에 chmod 설정을 적용한다는 것.

nnn : user권한 group권한 other권한

파일 사용 권한 r w x
설명 파일 읽기 파일 쓰기 파일 실행
권한 번호 $2^2$ $2^1$ $2^0$

(예)

나 : 읽기 쓰기 _ ⇒ 6

그룹 : 읽기 _ _ ⇒ 4

타인 : _ _ _ ⇒ 0

vim 명령어

Git

git init // 초기화, .git 폴더 생성

git config --global user.name "이름"
git config --global user.email "개인메일"
git config --list //확인

// —global 없으면 git init할 때마다 git config 설정해주어야 함.

git 영역

  • working area - staging area - git remote repository
    • working area
      • 사용자의 작업 중인 프로젝트의 공간
      • 새로 생성된 파일은 untracked 상태
      • git status통해 파일 추적 상태 확인 가능
    • staging area
      • commit 등록 대기 상태
      • git add를 통해 staging area에 등록
    • repository
      • git commit -m “커밋메세지”를 통해 repository에 등록된다.
    • Git
      • git push를 통해 git에 등록된다.

git 상태 status

  • git status
    • 상태 확인
    • 빨간색 : 관리 대상이 아님
    • 녹색 : 관리 대상 (add 통해서)
  • untracked
    • 아직 추적당하고 있지 않은 파일
    • 새로 만든 파일 혹은 git을 초기화했을 때
  • unmodified
    • git commit 후 상태
    • git clone 후 상태
  • staged
    • staging area에 반영된 상태
  • modified
    • git add 후 파일 수정한 상태

git commit

  • git add (파일 이름)
    • stage에 올림
    • add 취소
      • git reset (파일 이름)
  • git commit -m “커밋 메세지”
    • git repository 저장
    • git commit -am “커밋 메세지”
      • git add + commit은 처음 파일 생성 시만 별도로 사용하고, 그 후로 파일 수정 후에는 git commit -am 으로 add 안 하고 commit 가능
    • commit 취소
      • git reset (커밋 hashcode) —hard
      • git reset —soft
      • git revert (커밋 hashcode)
        • push후에 commit 취소
  • git log

    • commit 기록

    • commit hash값 첫 4글자만 쳐서 제한 가능

    • git log -p

      • 버전 간 차이를 보여줌

      • q로 종료

      • git diff (브랜치 1)..(브랜치 2)

        • 브랜치 간 변경사항을 보여줌
  • git checkout
    • git checkout (commit hash값)
      • 특정 커밋 버전으로 전환
    • git checkout (branch이름)
      • 특정 branch로 이동

Branch

  • git branch (branch 이름)
    • branch 생성
  • git checkout (branch 이름)
    • branch 이동
  • git checkout -b (branch 이름)
    • branch 생성 및 이동
  • git log --branches --decorate --graph --oneline
    • 모든 브랜치의 작업 상황(커밋) 보기
    • sourcetree로 대체 가능
  • git log A..B
    • A에 없는, B에서만 커밋된 커밋을 나타냄
  • git branch —list
    • 현재 branch 목록 확인

Branch 병합, 충돌

  • git merge B
    • A 위치에서 실행하여 B와 병합
  • git branch -d (branch 이름)
    • 브랜치 삭제 delete
  • 동일한 파일의 경우 충돌할 수 있지만 특정 함수를 기준으로 상, 하에 추가하면 충돌 발생하지 않음.
  • 충돌 Conflict
  • 같은 파일을 동시에 수정했을 때, 충돌 발생
  • 파일 수정 후 다시 커밋

Stash

파일 수정 후, add와 커밋 안 하고 브랜치 옮기면 git status에 따라다님

작업 중 잠깐 숨겨놓기 위해 사용하는 명령어

git stash apply

Git 원격저장소

  • 업로드 push

git remote add origin (원격 저장소 url)

origin : 주소 별명

git branch -M main

지금 현재 브랜치를 main으로 만듦

git push -u origin main

origin의 main 브랜치로 업로드(push)

git remote -v

저장소 위치 확인

  • 다운로드 pull

git clone <repository url> .

마지막 . : 현재 위치에 깃허브 디렉터리가 생성되지 않고 파일들만 다운로드


Refs

chmod

https://88240.tistory.com/13

git stage

https://iseunghan.tistory.com/322

https://velog.io/@kwonh/Git-Git-기초-기본-사용법-1-파일의상태-삭제-변경-커밋-히스토리-조회

git checkout

https://zoosso.tistory.com/729

728x90