하나씩 차근차근
article thumbnail
Published 2022. 12. 31. 10:04
Git - 3가지 영역 Git

프로그램을 개발하고 관리하기 위해서는 버전관리시스템인 Git 이 필요합니다.

앞으로 Springboot 프로젝트를 개발할때 Git 을 통해서 기록하고 관리를 할 것이며,

그 전에 Git 에 대해서 먼저 공부를 해보려고 합니다.

 

3가지 영역

  • Working Directory (작업영역) : git init 을 통해 작업영역을 설정하며, 파일의 변경을 감지
  • Staging Area (인덱스 영역) : 작업영역에서 git add 를 통해 변경된 파일들을 tree 형태의 목차로 관리
  • Repository (헤더 영역) : 인덱스 영역에서 git commit 을 통해 변경된 파일들을 최종적으로 기록

 

실습

이번에는 작업영역에서 파일을 만들고 인덱스 영역과 헤더 영역으로 기록을 해보겠습니다.

 

ex01 이라는 디렉토리를 하나 만든 뒤 이 디렉토리에서 마우스 우클릭을 해서 나오는 Git Bash Here 을 클릭합니다.

 

Git Bash Here 을 클릭하면 콘솔창이 뜨는데 콘솔창에서 git init 을 입력해서 git 을 시작합니다.

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01
$ git init
Initialized empty Git repository in C:/Users/TEST/Desktop/git_workspace/ex01/.git/

 

ex01 디렉토리에서 touch test1.txt 명령어를 통해 test1.txt 를 생성합니다.

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01 (master)
$ touch test1.txt

git status 를 통해 현재 작업영역의 변경사항을 감지할 수 있습니다.

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01 (master)
$ git status
On branch master

No commits yet

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

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

git status 를 입력하면 Untracked files : test1.txt 이라고 뜨는데

이는 test1.txt 파일이 인덱스 영역에 반영이 안되어 있기 때문입니다.

이 파일을 git add . 명령어를 사용해 인덱스 영역에 기록해보겠습니다.

(git add test1.txt 명령어도 사용가능)

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01 (master)
$ git add .

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01 (master)
$ git status
On branch master

No commits yet

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

git add . 명령어를 입력하고 git status 를 입력해보면 test1.txt 가 반영이 된 것을 볼 수 있습니다.

다음으로 git commit -m ("메세지") 를 사용해 test1.txt 파일을 헤더영역(Repository) 에 반영해보겠습니다.

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01 (master)
$ git commit -m "첫번째 파일"
[master (root-commit) 2f88209] 첫번째 파일
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1.txt

git commit 을 통해 커밋을 한 내역을 git log 명령어를 입력해서 확인할 수 있습니다.

TEST@DESKTOP-6UMU4VH MINGW64 ~/Desktop/git_workspace/ex01 (master)
$ git log
commit 2f8820928ac43e71fbd53963fe6c589d6a00c10f (HEAD -> master)
Author: jeehwan <tjtojan@naver.com>
Date:   Sat Dec 31 15:49:03 2022 +0900

    첫번째 파일

 

이 포스트는 유튜브에 올라온 메타코딩님의 Git 강의를 보고 정리한 내용입니다.
https://www.youtube.com/@metacoding

'Git' 카테고리의 다른 글

Git - clone 과 fetch  (0) 2023.01.03
Git - github 프로젝트 push 와 pull  (1) 2023.01.03
Git - 3 way merge  (0) 2023.01.03
Git - fast forward merge  (0) 2023.01.03
Git - reset과 reflog를 통한 복구  (1) 2022.12.31
profile

하나씩 차근차근

@jeehwan_lee

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!