Git Version

Source Code Management(SCM) Tool : 코드 관리 도구

Version Control System(VCS) : 버전 관리 시스템

버전을 통해 코드를 관리하는 도구

버전 관리를 하는 이유

  1. 언제든 과거로 돌아갈 수 있음
  2. 수정 이력을 확인할 수 있음

Git 명령어

0. 폴더생성

git 저장소로 만들 폴더 생성

1.git init

git 프로젝트(저장소)를 시작 설정 (폴더 위치)

Initialized empty Git repository in C:/Users/wo779/git_basic/.git/
 : init은 initialize의 약자 
  1. (master)

  2. .git폴더 생성

1-1. git 프로젝트를 종료 (중요)

  • .git 폴더 삭제
    • rm [파일명] : 파일 삭제 (remove의 약자)
    • rm -r [폴더명] : 폴더 삭제
    • rm -rf [폴더명] : 강제(확인없이) 폴더 삭제
    • rm -rf / : /(폴더) 삭제 (/는 최고 상위 폴더를 가리킴)
      • r은 recursively(재귀적)의 약자

2. git status

git의 현재 상태를 출력

  • 최초 상태
On branch master : master라는 브랜치에 있음

No commits yet : 아직 commit이 없음

nothing to commit (create/copy files and use "git add" to track)
 : commit할 게 없음
  • 파일/폴더 추가시 (touch a.txt)
...

untracked files: (추적되지 않은 파일)
	(use "git add <file>..." to include in what will be committed)
		a.txt (빨강색 글씨)

nothing added to commit but untracked files present (use "git add" to track)
 : commit하기 위해 추가된 파일이 없음, 그러나 추적되지 않은 파일은 있음
 
  • add 이후 (git add a. txt)
...

Changes to be committed:
commit할 변화들
	(use "git rm --cached <file>..." to unstage)
		new file:	a.txt (초록색 글씨)
  • commit 이후(git commit -m "first commit")
On branch master
nothing to commit, working tree clean

3. git add [파일명]

commit하기 위한 stage에 파일 추가 ==> tracked

  • git add .: 해당 디렉토리 아래 모든 파일을 add
  • git add [폴더명]: 해당 폴더 안의 모든 파일을 add
  • git add . : 모든 파일 및 디렉토리 add (.은 모든 파일, 디렉토리를 가리킴)
  • 여러 파일을 add하고 싶다면 git add css/app.css js/app.js 처럼 띄워쓰기 하면 됌

4.git commit -m "커밋메시지"

스냅샷 & 버전 생성

  • git commit -am "커밋메시지": add와 commit이 한번에 가능
    • track 되지 않은 파일은 불가능 (한번도 stage에 add되지 않은 파일은 불가능)

commit의 구성 요소

  • committer(author): commit을 찍은 사람
  • commit datetime(date): commit을 찍은 시간
  • commit message: commit에 대한 내용 (필수)

5. git config (–global / –system / –local / 등)

  • git config --global user.email "이메일": 사용자 이메일 설정
  • git config --global user.name "이름": 사용자 이름 설정
  • git config --global user.email: 사용자 이메일 출력
  • git config --global user.name: 사용자 이메일 출력
  • git config --unset user.name: 사용자 정보 삭제
  • git config --global --list: 사용자 정보 확인
  • git config --global http.version HTTP/1.1: HTTP 1.1버전 사용
  • git config --global http.version HTTP/2: HTTP 2버전 사용
  • git config http.postBuffer 524288000: post buffer 변경
  • git config --global http.postBuffer 157286400: post buffer 변경

6. git log

commit 목록(log) 출력

  • git log --oneline: 한 줄 출력(버전(커밋ID)과 커밋메시지 출력)
  • git log --stat: 커밋에 연루된 파일 포함 출력
  • git log -p : 커밋과 연루된 파일, 수정 내역 포함 출력

7. git show

하나의 commit에 대한 자세한 정보 출력

  • git show : 가장 최종 commit에 대한 정보 출력
  • git show [커밋ID] : 해당 commit에 대한 정보 출력


실습

  • pwd : 현재 위치 출력(print working directory)
  • cd [폴더명] : 폴더 변경(change directory)
    • cd .. : 상위 폴더로 이동
    • cd ~ : 홈 폴더로 이동 (~는 홈 디렉토리를 나타냄)
  • ls : 현재 폴더 내용물 출력 (list)
    • ls -al : 현재 폴더 모든 내용물 출력(숨김 파일 표시)
  • touch [파일명] : 파일 생성 (확장자명까지 포함)
  • nano [파일명]: 파일 내용 수정 (파일이 없어도 바로 생성해서 수정 가능)
  • echo [문자열] : command line 출력
    • echo [문자열] > [파일명] : 특정 파일에 기록 (본래 내용 삭제)
    • echo [문자열] >> [파일명] : 특정 파일에 추가 기록 (본래 내용 유지)
  • cat [파일명]: 파일 내용 출력
  • git diff: 파일 수정 내역 출력

  • git reset --hard [버전]: 해당 버전으로 reset (hard는 reset mode를 가리킴–협업시 중요)

  • git checkout [버전]: 과거 해당 버전으로 돌아가기 (삭제된 것 아님)
    • git checkout master: 본래로 돌아가기
  • git commit --global core.editor "에디터명": 해당 에디터를 기본으로 설정

  • git revert [버전]: 해당 버전을 revert (커밋 개별적으로 적용됨)