뚝딱쓱삭

GIT CLI 주요 명령어 모음 본문

개발기타/생산성

GIT CLI 주요 명령어 모음

별냥이 2018. 4. 12. 00:36
반응형

git config --list : 주요 환경설정 보기



1.시작하기


  git bash 안에서 실제 소스코드가 있는 폴더로 이동

  git init

  git add *.*

  git commit -m '첫번째 저장'


2.현재상태 확인하기


  git status : 현재 보관중인 파일 현황 보여주기

  git diff    : 변경된 파일 중 unstaged인 파일의 변경내용을 확인하기

  git diff --staged : staged상태인 파일을 확인하기


  git log : commit history확인하기

  git log -p : 각 commit의 diff결과 보여주기

  git log -2 : 최근 2개의 diff결과 보여주기

  git log --stat : 각 commit의 통계정보 보여주기

 

  master에 branch01읠 가져와서 병합

  git checkout master

  git merge test_1

 



3.Commit하기


  git commit : 커밋하기

  git commit -m "xxxx" : xxxx란 메세지로 커밋하기

  git commit -a : staged로 만들지 말고 바로 커밋하기


  git commit --amend : 방금 완료한 commit을 수정해야할 때, staged에 있는 내용을 사용하여 다시 commit (즉 overwrite)



4.되돌리기


  git checkout --파일명 : 최근 commit한 내용으로 복구함 (하지만 가급적 쓰지말고 stash와 branch를 사용)

  git reset HEAD 파일명 : staged된 파일을 unstaged로 변경



5.Branch

 

   git branch : 현재 branch상태 보여주기

   git branch -v : 각 branch의 commit message도 보여줌.

   git branch --merged : merged상태 branch만 보여줌

   git branch --no-merged : no merged상태 branch만 보여줌



   git branch test1 : test1로 branch생성(save as개념, git의 작업환경은 여전히 기존 환경에서 작업 중)

   git checkout test1 : test1 작업환경으로 이동   

   git checkout -b test1 : test1으로 branch를 만들면서 checkout까지 함

   git log  --oneline --graph --all : branch이력 보여주기

  

   git merge test0 : 현재 작업환경에 test0의 내용을 합침. 만일 test0이 더 나중버젼이면 현재 작업환경을 fast forward함


   git branch -d test9 : 필요없는 test9 브랜치를 삭제

   git branch -m new_branch_name : current branch의 이름을 변경

  


6. Stash

   작업 내용을 commit 대신 임시로 저장할 때 사용. 작업 내용의 인덱스가 체크아웃 중인 브랜치에 저장됨


   git add

   git stash

   git stash apply : 임시 저장한 내용을 다시 불러옴

   git stash drop : 임시저장한 내용 삭제

   git stash pop : apply & drop


7.기타


  7.1.삭제하기

      git rm : staged된 파일을 삭제함  (이후 commit해야함)

 

  7.2.이름바꾸기

      git mv 파일이름1 파일이름2  : 이름 바꿈

 

  7.3.예외사항 관리하기

      7.3.1.파일 무시하기

            cat .gitignore 명령으로 무시할 파일을 기입할 수 있다.

            예:

                *.[oa] : *.o나 *.a를 무시

                *~    : ~로 끝나는 모든 파일을 무시


반응형