Git - 1. 버전 관리 시작과 버전 만들기

BANG·2025년 9월 3일

git

목록 보기
1/7

버전 관리 시작

  • 특정 디렉토리를 버전 관리를 하고 싶으니 관리해달라 요청
$ git init .
  • .git 이란 디렉토리가 생김
  • .git 이란 디렉토리의 부모 디렉토리의 변화를 버전으로 만들면 .git의 내부에 알아서 저장됨
  • .git을 지우면 역사가 사라짐

버전 만들기(단일 파일)

working tree

  • 파일을 작업(수정 등)하는 곳

staging area

  • 버전으로 만들 때, 버전으로 만들 파일들을 올려놓기

repository

  • .git 디렉토리
  • 버전이 저장되는 곳

git status

  • git 상태 확인

  • No commits yet: 버전이 없음

  • Untracked files: 추적되지 않고 있는 파일

$ vi hello.txt

$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.txt

nothing added to commit but untracked files present (use "git add" to track)

git add 파일명

  • 파일을 staging area에 지정한 파일을 올려놓기

  • 파일을 버전으로 만들거라는 표시

  • Changes to be committed: 버전이 될 파일 목록

$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it


$ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt

git commit -m "~"

  • staging area의 파일들을 버전으로 만들기

  • working tree clean: 버전이 되지 않은 수정사항이 없음

  • nothing to commit: 버전으로 만들 파일이 없음

$ git commit -m "message 1"
[main (root-commit) 2eb09a5] message 1
 1 file changed, 1 insertion(+)
 create mode 100644 hello.txt


$ git status
On branch main
nothing to commit, working tree clean

git log

$ git log
commit ~~~~~93e312 (HEAD -> main)
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:21:52 2025 +0900

    message 1
  • Changes not staged for commit: staging area에 있지 않은 수정사항이 working tree에 존재
$ vi hello.txt


$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

no changes added to commit (use "git add" and/or "git commit -a")
  • 다시 stage에 올리고 커밋하기
$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it


$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   hello.txt


$ git commit -m "message 2"
[main 26eb89e] message 2
 Committer: unknown <1111@~~~~~.com>
 1 file changed, 1 insertion(+)


$ git status
On branch main
nothing to commit, working tree clean


$ git log
commit ~~~~~a4ec5 (HEAD -> main)
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:29:20 2025 +0900

    message 2

commit ~~~~~e312
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:21:52 2025 +0900

    message 1

버전 만들기(다중 파일)

  • 2개의 파일 모두 staging area에 올라가지 않은 상태
  • hello.txt는 이미 1회 이상 버전으로 관리해온 파일
    - git이 hello.txt 파일을 알고 있는 상태
  • hello2.txt는 한번도 버전 관리한 적이 없는 파일
  • Changes not staged for commit: 수정 내용이 staging area에 올라가지 않은 상태
  • Untracked files: 추적되지 않고 있는 파일
$ vi hello.txt
$ vi hello2.txt


$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello2.txt

git add 파일명

  • 파일들을 staging area 에 올려넣기
  • Changes to be committed: 버전이 될 파일 목록
    - modified: 마지막 버전 이후에 수정된 것
    • new file: 한 번도 버전관리 한 적 없는 신규 파일
$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it

$ git add hello2.txt
warning: in the working copy of 'hello2.txt', LF will be replaced by CRLF the next time Git touches it


$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   hello.txt
        new file:   hello2.txt

git commit -m "~"

$ git commit -m "message 3"
[main 69d4907] message 3
 Committer: unknown <1111@~~~~~.com>
 2 files changed, 2 insertions(+)
 create mode 100644 hello2.txt


$ git status
On branch main
nothing to commit, working tree clean


$ git log
commit ~~8452 (HEAD -> main)
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:43:16 2025 +0900

    message 3

commit ~~~ec5
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:29:20 2025 +0900

    message 2

commit ~~~312
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:21:52 2025 +0900

    message 1

git log --stat

  • git log에서 파일 목록도 확인
    - 2 files changed, 2 insertions(+) : 2개의 파일이 수정, 2줄이 추가됨
$ git log --stat
commit ~~452 (HEAD -> main)
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:43:16 2025 +0900

    message 3

 hello.txt  | 1 +
 hello2.txt | 1 +
 2 files changed, 2 insertions(+)

commit ~~ec5
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:29:20 2025 +0900

    message 2

 hello.txt | 1 +
 1 file changed, 1 insertion(+)

commit ~~~e312
Author: unknown <1111@~~~~~.com>
Date:   Wed Sep 3 20:21:52 2025 +0900
profile
Record Everything!!

0개의 댓글