๐Ÿ˜ข ์Šคํ„ฐ๋””๋…ธํŠธ(Git 7~8)

zoeยท2023๋…„ 4์›” 25์ผ
0

Git Graph

  • Installing Git Graph on VSCode : Git Extension ์—์„œ 'git graph' ๋กœ ๊ฒ€์ƒ‰ํ•˜์—ฌ ์„ค์น˜

  • Open HelloGit : HelloGit ์„ ์—ด์–ด์„œ Graph ํ™•์ธ (Branch ๋ณ„๋„๋กœ ํ™•์ธ ๊ฐ€๋Šฅ)




์‹ค์Šตํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ

  • Remote Repository ์ƒ์„ฑ : log_project ์ƒ์„ฑ

  • Remote Repository ์ฃผ์†Œ ๋ณต์‚ฌ

  • Local Repository ์— Clone : git_ws ํด๋”์— ๋ณต์ œ

 git clone https://zoe-0314:<token>@github.com/zoe-0314/log_project.git

  • ํŒŒ์ผ ์ถ”๊ฐ€ ํ›„ ์ €์žฅ : Control + D ํ‚ค๋กœ ์ž…๋ ฅํ•œ ๋‚ด์šฉ ์ €์žฅ
  • cat :
    - cat > : ํŒŒ์ผ์ด ์žˆ์œผ๋ฉด ํŒŒ์ผ์— ๋‚ด์šฉ ์ž…๋ ฅ ๊ฐ€๋Šฅ / ํŒŒ์ผ์ด ์—†๋Š” ๊ฒฝ์šฐ ํŒŒ์ผ์„ ์ƒ์„ฑ ํ›„ ๋‚ด์šฉ ์ž…๋ ฅ ๊ฐ€๋Šฅ / ํŒŒ์ผ ๋ฐ ๋‚ด์šฉ์ด ์žˆ์„ ๊ฒฝ์šฐ ์ƒˆ๋กœ์šด ๋‚ด์šฉ ๋ฎ์–ด์“ฐ๊ธฐ
    - cat : cat ๋’ค์— ์•„๋ฌด๊ฒƒ๋„ ์—†๋Š” ๊ฒฝ์šฐ์—๋Š” ์•ˆ์— ๋‚ด์šฉ์„ ๋ณด์—ฌ์คŒ
    - cat >> : ๋ฐ‘์— ์ด์–ด์„œ ๋‚ด์šฉ ์ž…๋ ฅ ๊ฐ€๋Šฅ
cd log_project
cat > hello.py
print('hello, world')

ctrl + d

cat hello.py
git add hello.py
git status
git commit -m 'create' hello.py

  • ํŒŒ์ผ ์ˆ˜์ • ํ›„ ์ €์žฅ
cat hello.py
cat > hello.py
print('hello, cat')

ctrl + d

git commit -m 'modify 1' hello.py
code .

  • Branch ์ƒ์„ฑ ํ›„ ์ด๋™
git checkout -b dev
git branch
cat hello.py
cat > hello.py
print('hello, dog')

ctrl + d

 git commit -m 'modify 2' hello.py




Git Log

  • Git Log : Branch๋ณ„ ๋ณ€๊ฒฝ์ด๋ ฅ์„ ๋ณผ ์ˆ˜ ์žˆ์Œ
git log

  • ์‹ค์Šต 1 (Git Log) main branch ๋กœ ์ด๋™
git checkout main
  • ์‹ค์Šต 1 (Git Log) main branch ๋กœ๊ทธ ํ™•์ธ
git log
  • ์‹ค์Šต 2 (Git Log) dev branch ๋กœ ์ด๋™
git checkout dev
  • ์‹ค์Šต 2 (Git Log) dev branch ๋กœ๊ทธ ํ™•์ธ
git log




Git Editor ์„ค์ •

  • Git Editor ์„ค์ • :
    -- wait ์˜ต์…˜์€ command line ์œผ๋กœ VSCode ๋ฅผ ์‹คํ–‰์‹œ์ผฐ์„ ๊ฒฝ์šฐ, VSCode ์ธ์Šคํ„ด์Šค๋ฅผ ๋‹ซ์„ ๋•Œ๊นŒ์ง€ command ๋ฅผ ๋Œ€๊ธฐ
git config --global core.editor <editorname> --wait
  • ์‹ค์Šต
git config --global core.editor "code --wait"
 git config --global core.editor




Git Diff Tool ์„ค์ •

  • Git Configuration ํŒŒ์ผ ์—ด๊ธฐ
git config --global -e

  • Git Diff ์„ค์ • ์ถ”๊ฐ€
[diff]
	tool = vscode
[difftool "vscode"]
	cmd = "code --wait --diff $LOCAL $REMOTE"
  • ์‹ค์Šต
 git config --global -e

Git Diff ์„ค์ • ์ฝ”๋“œ ๋ถ™์—ฌ๋„ฃ๊ธฐ



Git Diff

  • Git Diff - Local Branch ๊ฐ„ ๋น„๊ต(๋‘ branch์˜ ์ตœ์‹  ๋ฒ„์ „์˜ ์ฐจ์ด๋ฅผ ๋ณด์—ฌ์คŒ)
git diff <branch1><branch2>

  • ์‹ค์Šต 1 (Git Diff) Local Branch ๊ฐ„ ๋น„๊ต ์‹ค์Šต
cd log_project
cat hello.py
git checkout main
cat hello.py
git diff main dev
  • ์‹ค์Šต 2 (Git Diff) Local Branch ๊ฐ„ ๋น„๊ต ์‹ค์Šต
git difftool main dev




  • Git Diff - Commit๊ฐ„ ๋น„๊ต
git diff <commithash><commithash>

  • ์‹ค์Šต 1 (Git Diff) Commit ๊ฐ„ ๋น„๊ต ์‹ค์Šต
git difftool d0fd16c159351df237966d930ccfc2cdd967fc1c 35005fcecaef9a026253012239c15665c7a8a45d




  • Git Diff - ๋งˆ์ง€๋ง‰ Commit๊ณผ ์ด์ „ Commit ๋น„๊ต
git diff HEAD HEAD^

  • ์‹ค์Šต 1 (Git Diff) ๋งˆ์ง€๋ง‰ Commit ๊ณผ ์ด์ „ Commit ๋น„๊ต ์‹ค์Šต
git difftool HEAD HEAD^




  • Git Diff - ๋งˆ์ง€๋ง‰ Commit๊ณผ ํ˜„์žฌ ์ˆ˜์ •์‚ฌํ•ญ ํ™•์ธ
git diff HEAD

  • ์‹ค์Šต 1 (Git Diff) ๋งˆ์ง€๋ง‰ Commit ๊ณผ ์ด์ „ Commit ๋น„๊ต ์‹ค์Šต
git checkout main
cat hello.py
cat > hello.py
print('hello, pid')

ctrl + d

git difftool HEAD




  • Git Diff - Local and Remote ๊ฐ„ ๋น„๊ต
git diff <branch> origin/<branch2>

  • ์‹ค์Šต 1 ๋งˆ์ง€๋ง‰ Commit ๊ณผ ์ด์ „ Commit ๋น„๊ต ์‹ค์Šต : ์ผ๋‹จ ํ˜„์žฌ Main Branch ์ƒํƒœ๋ฅผ Remote Repository ๋กœ Push
git push origin main
  • ์‹ค์Šต 1 ๋งˆ์ง€๋ง‰ Commit ๊ณผ ์ด์ „ Commit ๋น„๊ต ์‹ค์Šต : ์•„๊นŒ ์ˆ˜์ •ํ•œ ํŒŒ์ผ์„ Commit (Local Repository ์˜ Main Branch ์—๋งŒ ๋ฐ˜์˜๋จ)
 git commit -m 'modify 3' hello.py
  • ์‹ค์Šต 1 ๋งˆ์ง€๋ง‰ Commit ๊ณผ ์ด์ „ Commit ๋น„๊ต ์‹ค์Šต : Local Repository ์™€ Remote Branch ๋น„๊ต
git difftool main origin/main
  • ์‹ค์Šต 2 Git Graph ํ™•์ธ : ํ˜„์žฌ ํด๋”๋ฅผ VSCode ๋กœ ์—ด๊ธฐ ์œ„ํ•ด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ช…๋ น์–ด ์ž…๋ ฅ

1. GitHub ์—์„œ Remote Repository ์ƒ์„ฑ

  • ์ด๋ฆ„ : diff_project
  • ์˜ต์…˜ : README.md

2. Local ์— Clone

  • ์œ„์น˜ : git_ws ํด๋”
git clone https://zoe-0314:<token>@github.com/zoe-0314/diff_project.git
ls

3. Local Repository ์—์„œ ํŒŒ์ผ ์ƒ์„ฑ ํ›„ Push

  • text.txt
  • ํŒŒ์ผ ๋‚ด์šฉ : my name is noma.
cd diff_project
cat > test.txt
my name is noma.

ctrl + d

git status
git add test.txt
git commit -m 'creat test.txt' test.txt
git push origin main

๐Ÿ’ก 4. Main Branch ์—์„œ ํŒŒ์ผ ์ˆ˜์ • ํ›„ ๋งˆ์ง€๋ง‰ commit ํ•œ ๋‚ด์šฉ๊ณผ ๋น„๊ต

  • ํŒŒ์ผ ์ˆ˜์ • : my name is zero
cat > test.txt
my name is zero

ctrl + d

git difftool HEAD

5. Main Branch ์—์„œ ์ˆ˜์ •ํ•œ ๋‚ด์šฉ์„ commit ํ•œ ๋’ค Remote Server ์™€ ๋น„๊ต

git add test.txt
git commit -m 'modify 1' test.txt
git difftool main origin/main

6. Dev Branch ์ƒ์„ฑ ํ›„ ์ด๋™, ํŒŒ์ผ์„ ์ˆ˜์ •ํ•œ ๋’ค Master Branch ์™€ ๋น„๊ต

  • Branch ์ด๋ฆ„ : dev
  • ํŒŒ์ผ ์ˆ˜์ • : my name is base. (commit)
git checkout -b dev
cat > test.txt
my name is base

ctrl + d

git status
git add test.txt
git commit -m 'modify 2' test.txt
git difftool main dev

7. Dev Branch ์—์„œ ๋‘๋ฒˆ์งธ commit ๊ณผ ๋งˆ์ง€๋ง‰ commit ๋น„๊ต

  • ๋‘๋ฒˆ์งธ Commit Message : create test.txt
  • ๋งˆ์ง€๋ง‰ Commit Message : modify name - base
git log
git difftool c14364d3033633eb2ae2dfb42d6845e8d84364ce 0709176b89ffa31e00933a3256f8a8f3191ca51f

8. Git Grpah ํ™•์ธ

  • VSCode ์—์„œ diff_project ์˜ Git Graph ๋ฅผ Branch ๋ณ„๋กœ ํ™•์ธ

์‹ค์Šตํ™˜๊ฒฝ ๋งŒ๋“ค๊ธฐ

  • Remote Repository ์ƒ์„ฑ : merge_project ์ƒ์„ฑ

  • Local Repository ์— Clone : git_ws ํด๋”์— ๋ณต์ œ

git clone https://zoe-0314:<token>@github.com/zoe-0314/merge_project.git
cd merge_project
ls
  • ํŒŒ์ผ ์ถ”๊ฐ€ ํ›„ ์ €์žฅ
cat > test.txt
my name is noma.

ctrl + d

git status
git add test.txt
git commit -m 'create' test.txt
  • dev branch ์ƒ์„ฑํ•˜์—ฌ ํŒŒ์ผ ์ˆ˜์ •
git checkout -b dev
cat >> test.txt
are you?

ctrl + d

cat test.txt
git add test.txt
git commit -m 'modify 1' test.txt
git status
  • Git Log ํ™•์ธ
git log




Merge Tool ์„ค์ •

  • Git Configuration ํŒŒ์ผ ์—ด๊ธฐ
git config --global -e




  • Git Merge ์„ค์ • ์ถ”๊ฐ€
[merge]
	tool = vscode
[mergetool "vscode"]
	cmd = "code --wait $MERGED"




Merge

  • Git Merge : ํ˜„์žฌ ์œ„์น˜ํ•œ Branch์— ๋‹ค๋ฅธ Branch๋ฅผ ํ†ตํ•ฉ
git merge <branchname>

  • Main Branch๋กœ ์ด๋™
git checkout main
cat test.txt
  • Dev Branch Merge
git merge dev
cat test.txt
  • Log : Merge ๊ฒฐ๊ณผ ํ™•์ธ
git log




Conflict

  • Merge Conflict : Branch๋ฅผ Mergeํ•˜๋Š” ๊ณผ์ •์—์„œ ์ถฉ๋Œ์ด ๋‚  ์ˆ˜ ์žˆ์Œ. ํ˜น์€ Push, Pullํ•˜๋Š” ๊ณผ์ •์—์„œ๋„ ์ถฉ๋Œ์ด ์ผ์–ด๋‚  ์ˆ˜ ์žˆ์Œ

  • Main Branch์—์„œ ํŒŒ์ผ ์ˆ˜์ • : Hello, noma ๋ฅผ ์ƒ์„ฑ
git branch
cat test.txt
cat > test.txt
hello, noma

ctrl + d

git commit -m 'reset' test.txt
cat test.txt
  • Conflict Test ๋ฅผ ์œ„ํ•œ Branch ์ƒ์„ฑ : Hello, noma ๋ฅผ ์นดํ”ผ (์ด๋™์€ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.)
git branch dev2
git branch
  • Main Branch ์—์„œ ํŒŒ์ผ ์ˆ˜์ • : Hello, zero ๋ฅผ ์ƒ์„ฑ
cat > test.txt
hello, zero

ctrl + d

git commit -m 'modify -zero' test.txt
cat test.txt
  • Dev2 Branch ์—์„œ ํŒŒ์ผ ์ˆ˜์ •
git checkout dev2
cat test.txt
cat > test.txt
hello, base

ctrl + d

cat test.txt
git commit -m 'modify base' test.txt
  • Main Branch ์—์„œ Dev2 Merge : ์ด๋•Œ ์–‘์ชฝ์ด ๊ฐ™์€ ํŒŒ์ผ์˜ ๊ฐ™์€ ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— Conflict ๋ฐœ์ƒ
git checkout main
git merge dev2
  • MergeTool ์‹คํ–‰ : Conflict ๋ฐœ์ƒ ์ดํ›„ ์•„๋ž˜์™€ ๊ฐ™์ด MergeTool ์„ ์‹คํ–‰ํ•˜๋ฉด Conflict ๋‚œ ํŒŒ์ผ๋“ค์ด ์ฐจ๋ก€๋กœ ์—ด๋ฆผ
git mergetool
  • VSCode ์—์„œ Conflict ํŒŒ์ผ ์ˆ˜์ • : Main Branch ์™€ Dev2 Branch ์˜ Diff ๋ฅผ <<<<, ====, >>>> ๋กœ ํ‘œ์‹œ

  • ๋‘˜ ์ค‘ ๋งž๋Š” ์ฝ”๋“œ๋ฅผ ์„ ํƒํ•˜์—ฌ ์ˆ˜์ •ํ•˜๊ณ  ์ €์žฅ.(Diff ํ‘œ์‹œ ๋ถ€๋ถ„๋„ ์‚ญ์ œ)

  • Conflict ํ•ด์ œ : git add + git commit
git status
git add test.txt
git commit
  • Commit Message ์ €์žฅ ํ›„ ์™„๋ฃŒ

  • Git Log ๋กœ ํ™•์ธ

cat test.txt
git log

๐Ÿ’ก 1. Local Repository ์ƒ์„ฑ

  • ์œ„์น˜ : git_ws ํด๋” ํ•˜์œ„
  • ์ด๋ฆ„ : conflict_project
 mkdir conflict_project
cd conflict_project
git init

๐Ÿ’ก 2. Merge ์‹ค์Šต

  • Default Branch ์ด๋ฆ„ ํ™•์ธ : main or master
  • [master] ์—์„œ conflict.txt ์ƒ์„ฑ ํ›„ commit : This is
cat > conflict.txt
This is

ctrl + d

cat conflict.txt
git status
git add conflict.txt
git commit -m 'create' conflict.txt
  • [main] ์—์„œ Branch ์ƒ์„ฑ ํ›„ ์ด๋™ : dev
git checkout -b dev
  • [dev] ์—์„œ conflict.txt ์ˆ˜์ • ํ›„ commit : This is merge test.
cat > conflict.txt
This is merge test.
cat conflict.txt
git add conflict.txt
git commit -m 'modify' conflict.txt
  • [main] ์—์„œ [dev] Merge
git checkout master
cat conflict.txt
git merge dev
cat conflict.txt

3. Conflict ์ƒํ™ฉ ๋งŒ๋“ค๊ธฐ

  • [main] ์—์„œ Branch ์ƒ์„ฑ (์ด๋™ X) : dev2
git branch dev2
  • [main] ์—์„œ conflict.txt ์ˆ˜์ • ํ›„ commit : This is conflict test
cat > conflict.txt
This is conflict test.

ctrl + d

cat conflict.txt
git add conflict.txt
git commit -m 'modify -conflict' conflict.txt
  • [dev2] ์—์„œ conflict.txt ์ˆ˜์ • ํ›„ commit : This is log test.
git checkout dev2
cat conflict.txt
cat > conflict.txt
This is log test.

ctrl + d

git add conflict.txt
git commit -m 'modify -log' conflict.txt
  • [main] ์—์„œ [dev2] Merge : Conflict ๋ฐœ์ƒ ํ™•์ธ
git checkout master
git merge dev2

4. Conflict ํ•ด๊ฒฐ

  • Conflict ํ•ด๊ฒฐ : This is conflict test.
git mergetool
git add conflict.txt
git commit
cat conflict.txt
  • Log ๋กœ ํ™•์ธ
git log



์ƒ์†Œํ•˜๋‹ค..์–ด๋ ต..

๐Ÿ’ป ์ถœ์ฒ˜ : ์ œ๋กœ๋ฒ ์ด์Šค ๋ฐ์ดํ„ฐ ์ทจ์—… ์Šค์ฟจ

profile
#๋ฐ์ดํ„ฐ๋ถ„์„ #ํผํฌ๋จผ์Šค๋งˆ์ผ€ํŒ… #๋ฐ์ดํ„ฐ #๋””์ง€ํ„ธ๋งˆ์ผ€ํŒ…

0๊ฐœ์˜ ๋Œ“๊ธ€