[Git] 자주 쓰는 git 명령어 정리 📟

Inah-_-·2021년 4월 4일
0

Github

목록 보기
2/2
post-thumbnail

Git 기본 명령어

Git init

.git 파일 생성, 프로젝트 폴더에 git을 심어주는 역할

git init

Git add

git add inah.text # inah.text 파일 stage
git add . # 모든 파일 stage

Git commit

git commit -m "commit message"
git commit -am "add and commit" # 수정한 파일에 add와 commit 동시에 하기

Git push

git 원격 저장소에 반영하기

git push origin main
git push

Git pull

git 원격 저장소의 파일을 최신버전으로 가져오기

git pull origin main
git pull

Branch

작업을 진행중인 main branch에서 가지를 나누어 독립적인 작업을 할 때에 사용,
각각의 branch는 다른 branch의 영향을 받지 않는다.

Git branch

git branch 목록 보기

git branch

Git branch 생성

git branch <new branch name>

Branch 이동

git checkout <branch name>

Git checkout -b

현재 브랜치에서 새로운 브랜치를 생성 후 이동하기

git checkout -b <new branch name>

Git branch -m

브랜치명 변경하기

git branch -m <old branch name> <new branch name>

Git branch -d

브랜치 삭제하기

git branch -d <branch name>

Git Reset

저장소에 잘못 반영 되었을 때 (Push) 되돌리기

git reset <option> <commit id>

Reset Option

  • hard
    돌아가려는 커밋 이력 이후의 모든 내용을 삭제한다. 그 다음 commit들도 모두 지워진다.
  • soft
    돌아가려는 커밋 이력으로 되돌아 가지만, 그 다음 commit들은 지워지지 않는다.
    그 다음 commit으로 돌아갈 수 있다.
  • mixed
    돌아가려는 이력으로 돌아가고 이후 내용들이 그대로 있는 상태에서 인덱스만 초기화되어 add를 처음부터 다시 해줘야 한다.

[1] git log 사용하여 되돌리고 싶은 commit 시점의 id값 찾아내기
[2] git reset <hard><soft><mixed> 44a8

Git revert

commit은 유지하면서 내용만 rollback,
원격 저장소까지 push가 진행 됐을 때 사용한다.

git revert <commit id>
profile
Backend Developer

0개의 댓글