[cheatsheet] git

boychaboy·2023년 6월 9일
0

personal cheatsheet

목록 보기
3/7

Large file detected error

git log에서 커밋했던 이력을 확인한 후에

git log

해당파일을 올린 상태로 커밋했던 내역을 하고

git reset --mixed HEAD^ // 1개의 이력 삭제
git reset --mixed HEAD~5 // 5개의 이력 삭제

다시 커밋하면 된다.

Git Message

https://www.conventionalcommits.org/en/v1.0.0/#summary

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Type

  • feat - a new feature is introduced with the changes
  • fix - a bug fix has occured
  • chore - changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)
  • refactor – refactored code that neither fixes a bug nor adds a feature
  • docs - updates to documentation such as a the README or other markdown files
  • style - changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on
  • test - including new or correcting previous tests
  • perf - performance improvements
  • ci – continuous integration related
  • build - changes that affect the build system or external dependencies
  • revert – reverts a previous commit

Rules

  • type 뒤에 !를 붙이면 major한 change로 본다. (ex: feat!:~ )
  • scope: additional contextual information

ex)

fix: prevent racing of requests

Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.

Remove timeouts which were used to mitigate the racing issue but are
obsolete now.

Reviewed-by: Z
Refs: #123

Track, Modify and Stage

git commit -am “message’ # 한 번 커밋한 파일만 가능!

  • add + commit

git commit —-amend

  • edit last commit

git restore <file>

  • 수정한 내용 취소하고 가장 최신 버전 상태로 되돌리기
  • modified → unmodified

git restore —-staged <file>

  • staged → modified
  • git add <file> 을 취소하고 싶을 때

git reset HEAD^

  • 최신 커밋 되돌리기
    • --soft : 최근 커밋을 하기 전 상태로 되돌리기
    • —mixed : 최근 커밋 + 스테이징 전으로 되돌리기 (default)
    • —hard : 최근 커밋 + 스테이징 + 파일 수정 전으로 되돌리기
  • git reset HEAD~3 : 최근 3개의 커밋 취소
  • git reset <커밋 해시>: 특정 커밋 버전으로 되돌리기

git revert <커밋 해시>

  • 취소하고 특정 커밋으로 되돌리면서, 되돌리는 커밋 만들기

Branch and Merge

git log --oneline --branches

  • 각 브랜치의 커밋 내용을 한번에 볼 수 있음 (원래는 자기 브랜치 커밋밖에 못봄)
  • ⭐️ **git log --oneline --branches --graph**
    • 그래프 형태로 보기 쉽게 출력
        * e6c5301 apple content 4
        | * 44adcd0 master content 4
        |/
        * 65220d9 work 3
        * 89df040 work 2
        * 0d24307 work 1

git log master..apple

  • master 브랜치에는 없고, apple 브랜치에만 있는 커밋을 보여줌
    commit e6c53017db251a0f291ed922918f51d94a263f29
    Author: younghoon-j <younghoon.j@navercorp.com>
    Date:   Fri Apr 28 11:59:46 2023 +0900
    
        apple content 4

git init manual-2

  • mkdir manual-2 + git init

git merge o2 —no-edit

  • 커밋 메세지 수정 없이 병합

git stash

  • 작업하던 파일을 잠시 감춰두고 다른 작업을 해야할 때. 필요한 작업을 끝낸 후에 다시 감춰둔 파일을 꺼내올 수 있다.
  • 파일이 tracked 상태여야 한다.
  • 여러번 stash할 경우 각 버전은 stack의 형태로 쌓이게 된다.
  • git stash pop: 꺼내오기
  • git stash apply: 현재 수정하던 내용은 그대로 둔 채 가져오기
  • git stash drop: 목록에서 가장 최근 항목 삭제

Remote <> Local

git remote add origin <http/ssh>

  • 원격 저장소에 origin을 추가하겠다. (http/ssh 주소를 대신해서 부를 이름)
  • git remote -v 연결된 저장소 확인

git push -u origin main

  • 지역 저장소의 main 브랜치를 원격 저장소의 origin 브랜치로 푸시해라
  • -u 옵션은 둘을 연결하기 위한 것으로 처음에 한번만 사용하면 됨

git fetch

  • 원격 브랜치에 어떤 변화가 있었는지 그 정보만 가져옴. 다른 사람이 수정한 소스를 한번 더 훑어보고 합치고 싶을 때 사용
  • git fetch origin <remote_branch>로 새로 만들어진 원격 브랜치를 가져올 수 있음
  • git checkout FETCH_HEAD: fetch로 가져온 원격 브랜치로 이동해서 수정사항을 확인
profile
no vim no code

0개의 댓글