# Branch?
같은 뿌리에서 나왔지만 서로 다른 역사를 써가는 애들을 말함
# 실습환경 구축
82109@DESKTOP-OO924JS MINGW64 ~
$ mkdir manual
82109@DESKTOP-OO924JS MINGW64 ~
$ cd manual
82109@DESKTOP-OO924JS MINGW64 ~/manual
$ git init
Initialized empty Git repository in C:/Users/82109/manual/.git/
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ ls -al
total 24
drwxr-xr-x 1 82109 197609 0 Dec 11 18:55 ./
drwxr-xr-x 1 82109 197609 0 Dec 11 18:55 ../
drwxr-xr-x 1 82109 197609 0 Dec 11 18:55 .git/
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
work.txt
nothing added to commit but untracked files present (use "git add" to track)
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git add work.txt
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git commin -m "Work 1"
git: 'commin' is not a git command. See 'git --help'.
The most similar command is
commit
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git add work.txt
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git commit -m "Work 2"
[master (root-commit) 385f0cb] Work 2
1 file changed, 2 insertions(+)
create mode 100644 work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git add work.txt
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git commit -m "Work 3"
[master 4095dd5] Work 3
1 file changed, 1 insertion(+)
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git log -p
commit 4095dd58ad9eda58ad7344641d65da61dd719f46 (HEAD -> master)
Author: Jang.hyunjeong <jang.hyunjeong01@gmail.com>
Date: Sat Dec 11 18:58:05 2021 +0900
Work 3
diff --git a/work.txt b/work.txt
index 727541b..f261ea5 100644
--- a/work.txt
+++ b/work.txt
@@ -1,2 +1,3 @@
+content 3
content 2
content 1
commit 385f0cbc2fa3e2308b140cbb6ca38d145cc0b486
Author: Jang.hyunjeong <jang.hyunjeong01@gmail.com>
Date: Sat Dec 11 18:57:14 2021 +0900
Work 2
diff --git a/work.txt b/work.txt
new file mode 100644
:...skipping...
commit 4095dd58ad9eda58ad7344641d65da61dd719f46 (HEAD -> master)
Author: Jang.hyunjeong <jang.hyunjeong01@gmail.com>
Date: Sat Dec 11 18:58:05 2021 +0900
Work 3
diff --git a/work.txt b/work.txt
index 727541b..f261ea5 100644
--- a/work.txt
+++ b/work.txt
@@ -1,2 +1,3 @@
+content 3
content 2
content 1
commit 385f0cbc2fa3e2308b140cbb6ca38d145cc0b486
Author: Jang.hyunjeong <jang.hyunjeong01@gmail.com>
Date: Sat Dec 11 18:57:14 2021 +0900
Work 2
diff --git a/work.txt b/work.txt
new file mode 100644
index 0000000..727541b
--- /dev/null
+++ b/work.txt
@@ -0,0 +1,2 @@
+content 2
+content 1
1) mkdir manual
- manual이라는 이름의 폴더를 만든다.
2) cd manual
- manual이라는 이름의 폴더에 접근
3) git init
- 현재 경로에 git 초기화
4) ls -al
- 현재 경로의 파일 정보
5) nano work.txt
- work.txt 라는 파일을 만들고, 내용 수정
6) git status
- 현재 폴더의 git 상태보기
7) git add work.txt
- working tree 에 있는 work.txt를 staging area 에 추가
8) git commit -m "Work 1"
- "Work 1"이란 메세지와 함께 깃 커밋
9) git log -p
- 파일 변경사항과 함께 git log 보기
# 브랜치의 사용법
상황 ) apple용, google용, ms용 브랜치를 만들어보자
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git log --all --graph --oneline
* 4095dd5 (HEAD -> master) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git branch
* master
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git branch apple
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git log --all --graph --oneline
* 4095dd5 (HEAD -> master, apple) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git branch google
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git branch ms
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git log --all --graph --oneline
* 4095dd5 (HEAD -> master, ms, google, apple) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git commit -am "master work 4"
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
[master d84a8f3] master work 4
1 file changed, 1 insertion(+)
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git log --all --graph --oneline
* d84a8f3 (HEAD -> master) master work 4
* 4095dd5 (ms, google, apple) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git checkout apple
Switched to branch 'apple'
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git log --all -graph --oneline
fatal: unrecognized argument: -graph
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git log --all --graph --oneline
* d84a8f3 (master) master work 4
* 4095dd5 (HEAD -> apple, ms, google) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git checkout master
Switched to branch 'master'
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git log --all --graph --oneline
* d84a8f3 (HEAD -> master) master work 4
* 4095dd5 (ms, google, apple) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$
1) git log --all --graph --oneline
- --all : 우리가 만들게 될 모든 브랜치가 보임
- --graph : 시각적으로 보임
- --oneline : 버전을 한줄로 나오게함
- 여기 영역을 유심있게 보면서 head의 위치, 추가되는 branch등을 살펴보자.
- 브랜치 생성 시, () 안의 글자에 유의 apple 이 생김
2) git branch
- master branch를 만든다.
3) git branch apple
- apple 이란 이름의 브랜치를 만든다.
4) git checkout apple
- apple 브랜치로 이동
5) git checkout master
- master branch로 이동 (가장 최신 커밋 내역)
# 브랜치를 이동하며 작업하기 - git checkout
82109@DESKTOP-OO924JS MINGW64 ~/manual (master)
$ git checkout apple
Switched to branch 'apple'
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ nano apple.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git add .
warning: LF will be replaced by CRLF in apple.txt.
The file will have its original line endings in your working directory
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git commit -m "apple work 4"
[apple 6ef9c22] apple work 4
2 files changed, 2 insertions(+)
create mode 100644 apple.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git log --all --graph --oneline
* 6ef9c22 (HEAD -> apple) apple work 4
| * d84a8f3 (master) master work 4
|/
* 4095dd5 (ms, google) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (apple)
$ git checkout google
Switched to branch 'google'
82109@DESKTOP-OO924JS MINGW64 ~/manual (google)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (google)
$ nano google.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (google)
$ git add .
warning: LF will be replaced by CRLF in google.txt.
The file will have its original line endings in your working directory
82109@DESKTOP-OO924JS MINGW64 ~/manual (google)
$ git commit -m "google work 4"
[google 83bdcc8] google work 4
2 files changed, 2 insertions(+)
create mode 100644 google.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (google)
$ git log --all --graph --oneline
* 83bdcc8 (HEAD -> google) google work 4
| * 6ef9c22 (apple) apple work 4
|/
| * d84a8f3 (master) master work 4
|/
* 4095dd5 (ms) Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (google)
$ git checkout ms
Switched to branch 'ms'
82109@DESKTOP-OO924JS MINGW64 ~/manual (ms)
$ nano work.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (ms)
$ nano ms.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (ms)
$ git add .
warning: LF will be replaced by CRLF in ms.txt.
The file will have its original line endings in your working directory
82109@DESKTOP-OO924JS MINGW64 ~/manual (ms)
$ git commit -m "ms work 4"
[ms 1cceb92] ms work 4
2 files changed, 2 insertions(+)
create mode 100644 ms.txt
82109@DESKTOP-OO924JS MINGW64 ~/manual (ms)
$ git log --all --graph --oneline
* 1cceb92 (HEAD -> ms) ms work 4
| * 83bdcc8 (google) google work 4
|/
| * 6ef9c22 (apple) apple work 4
|/
| * d84a8f3 (master) master work 4
|/
* 4095dd5 Work 3
* 385f0cb Work 2
82109@DESKTOP-OO924JS MINGW64 ~/manual (ms)
1) git checkout apple
- apple이란 브랜치로 이동.
2) git log --all --graph --oneline
- 여기 영역에서 log 가 어떻게 변하는지 유심있게 보자.
- checkout 이후 각각의 브랜치에 commit 하면, 각각의 변경사항이 각각의 branch에 저장됨을 알 수있다.
'Note > 생활코딩 GIT' 카테고리의 다른 글
[생활코딩_GIT] 03. CLI Branch & conflict - #3 3way merge (0) | 2021.12.14 |
---|---|
[생활코딩_GIT] 03. CLI Branch & conflict - #2 브랜치 병합 (0) | 2021.12.12 |
생활코딩_GIT_02. CLI 버전관리 - #4 git 버전 이동/ 버전 삭제 / 버전 되돌리기 (0) | 2021.12.10 |
생활코딩_GIT_02. CLI 버전관리 - #3 버전만들기 (0) | 2021.12.10 |
생활코딩_GIT_02. CLI 버전관리 - #2 저장소 Repository 만들기 (0) | 2021.12.10 |