์ค ๋ ์ ๋ณด
ํค๋ณด๋์์ return ํค๋ฅผ ๋๋ฅผ ๋๋ง๋ค ์ค ๋์ด๋ผ๋ ๋ณด์ด์ง ์๋ ๋ฌธ์๊ฐ ์ฝ์ ๋ฉ๋๋ค. ์ด์ ์ฒด์ ๋ง๋ค ์ค ๋์ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํฉ๋๋ค.
Git๊ณผ GitHub๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ๋ฅผ ํ์ ํ ๋, ์๋ฅผ ๋ค์ด Windows ๋จธ์ ์์ ์์ ์ค์ด๊ณ ํ๋ ฅ์๊ฐ macOS์์ ๋ณ๊ฒฝํ ๊ฒฝ์ฐ Git์์ ์๊ธฐ์น ์์ ๊ฒฐ๊ณผ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
์ค ๋์ ์๋์ผ๋ก ์ฒ๋ฆฌํ๋๋ก Git์ ๊ตฌ์ฑํ๋ฉด ๋ค๋ฅธ ์ด์ ์ฒด์ ๋ฅผ ์ฌ์ฉํ๋ ์ฌ๋๊ณผ ํจ๊ณผ์ ์ผ๋ก ํ์ ํ ์ ์์ต๋๋ค.
์ค ๋์ ์ ์ญ ์ค์
git config core.autocrlf
๋ช
๋ น์ Git์์ ์ค ๋ ์ฒ๋ฆฌ ๋ฐฉ๋ฒ์ ๋ณ๊ฒฝํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. ๋จ์ผ ์ธ์๋ฅผ ์ฌ์ฉํฉ๋๋ค.
macOS์์๋ ๊ตฌ์ฑ์ input
(์)๋ฅผ ์ ๋ฌํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. ์์:
$ git config --global core.autocrlf input
# Configure Git to ensure line endings in files you checkout are correct for macOS
Windows์์๋ ๊ตฌ์ฑ์ true
(์)๋ฅผ ์ ๋ฌํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. ์์:
$ git config --global core.autocrlf true
# Configure Git to ensure line endings in files you checkout are correct for Windows.
# For compatibility, line endings are converted to Unix style when you commit files.
Linux์์๋ ๊ตฌ์ฑ์ input
์ ์ ๋ฌํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค. ์์:
$ git config --global core.autocrlf input
# Configure Git to ensure line endings in files you checkout are correct for Linux
๋ฆฌํฌ์งํ ๋ฆฌ๋ณ ์ค์
ํ์์ ๋ฐ๋ผ .gitattributes
ํ์ผ์ ๊ตฌ์ฑํ์ฌ Git์ด ํน์ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ค ๋์ ์ฝ๋ ๋ฐฉ๋ฒ์ ๊ด๋ฆฌํ ์ ์์ต๋๋ค. ์ด ํ์ผ์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ปค๋ฐํ๋ฉด ๋ชจ๋ ๋ฆฌํฌ์งํ ๋ฆฌ ๊ธฐ์ฌ์์ core.autocrlf
์ค์ ์ด ์ฌ์ ์๋ฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด Git ์ค์ ๋ฐ ํ๊ฒฝ์ ๊ด๊ณ์์ด ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์ผ๊ด๋ ๋์์ด ๋ณด์ฅ๋ฉ๋๋ค.
๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ฃจํธ์ .gitattributes
ํ์ผ์ ๋ง๋ค๊ณ ๋ค๋ฅธ ํ์ผ์ฒ๋ผ ์ปค๋ฐํด์ผ ํฉ๋๋ค.
.gitattributes
ํ์ผ์ ๋ ๊ฐ์ ์ด์ด ์๋ ํ
์ด๋ธ์ฒ๋ผ ๋ณด์
๋๋ค.
- ์ผ์ชฝ์๋ Git์์ ์ผ์น์ํฌ ํ์ผ ์ด๋ฆ์ด ์์ต๋๋ค.
- ์ค๋ฅธ์ชฝ์๋ Git์์ ํด๋น ํ์ผ์ ์ฌ์ฉํด์ผ ํ๋ ์ค ๋ ๊ตฌ์ฑ์ด ์์ต๋๋ค.
์์
.gitattributes
ํ์ผ์ ์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๋ฆฌํฌ์งํ ๋ฆฌ ํ
ํ๋ฆฟ์ผ๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
ํ์ผ์ด ๊ณต๋ฐฑ์ผ๋ก ๊ตฌ๋ถ๋์ด ์ผ์น๋ ๋ค์(*.c
, *.sln
, *.png
), ์ค์ ์ด ์ง์ ๋ฉ๋๋ค(text
, text eol=crlf
, binary
). ์๋์์ ๋ช ๊ฐ์ง ๊ฐ๋ฅํ ์ค์ ์ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
-
text=auto
Git์ ๊ฐ์ฅ ์ข๋ค๊ณ ์๊ฐํ๋ ๋ฐฉ์์ผ๋ก ํ์ผ์ ์ฒ๋ฆฌํฉ๋๋ค. ์ข์ ๊ธฐ๋ณธ ์ต์ ์ ๋๋ค. -
text eol=crlf
Git์ ์ฒดํฌ ์์ ์ ํญ์ ์ค ๋์CRLF
(์ผ)๋ก ๋ณํํฉ๋๋ค. OSX ๋๋ Linux์์๋CRLF
๋์ ์ ์งํด์ผ ํ๋ ํ์ผ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค. -
text eol=lf
Git์ ์ฒดํฌ ์์ ์ ํญ์ ์ค ๋์LF
(์ผ)๋ก ๋ณํํฉ๋๋ค. Windows์์๋ LF ๋์ ์ ์งํด์ผ ํ๋ ํ์ผ์ ์ฌ์ฉํด์ผ ํฉ๋๋ค. -
binary
Git์ ์ง์ ๋ ํ์ผ์ด ํ ์คํธ๊ฐ ์๋๋ผ๋ ๊ฒ์ ์ธ์ํ๋ฏ๋ก ๋ณ๊ฒฝํ๋ ค๊ณ ํ๋ฉด ์ ๋ฉ๋๋ค.binary
์ค์ ์-text -diff
์ ๋ณ์นญ์ด๊ธฐ๋ ํฉ๋๋ค.
์ค ๋์ ๋ณ๊ฒฝํ ํ ๋ฆฌํฌ์งํ ๋ฆฌ ์๋ก ๊ณ ์นจ
core.autocrlf
์ต์
์ ์ค์ ํ๊ฑฐ๋ .gitattributes
ํ์ผ์ ์ปค๋ฐํ๋ฉด, Git์์ ์ ๊ตฌ์ฑ๊ณผ ์ผ์นํ๋๋ก ์ค ๋์ ์๋์ผ๋ก ๋ณ๊ฒฝํฉ๋๋ค. ์์ ํ์ง ์์ ํ์ผ์ ๋ณ๊ฒฝ ๋ด์ฉ์ Git์์ ๋ณด๊ณ ํ ์ ์์ต๋๋ค.
๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ชจ๋ ์ค ๋์ ์ ๊ตฌ์ฑ๊ณผ ์ผ์นํ๋๋ก ํ๋ ค๋ฉด, Git์ ์ฌ์ฉํ์ฌ ํ์ผ์ ๋ฐฑ์ ํ ๋ค์ ๋ชจ๋ ํ์ผ์ ์ ๊ฑฐํ๊ณ ๋ณต์ํ์ฌ ์ค ๋์ ์ ๊ทํํฉ๋๋ค.
-
๋ณ๊ฒฝ ๋ด์ฉ์ ์ถ๊ฐํ๊ฑฐ๋ ์ปค๋ฐํ๊ธฐ ์ ์ Git์ด ๊ตฌ์ฑ์ ์ฌ๋ฐ๋ฅด๊ฒ ์ ์ฉํ๋์ง ํ์ธํฉ๋๋ค. ์๋ฅผ ๋ค์ด Git์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ํ์ผ์ด ํ ์คํธ ๋๋ ์ด์ง ํ์ผ์ธ์ง ์ฌ๋ถ๋ฅผ ์๋์ผ๋ก ๊ฒฐ์ ํฉ๋๋ค. ๋ฆฌํฌ์งํ ๋ฆฌ์์ ์ด์ง ํ์ผ์ด ์์๋๋ ๊ฒ์ ๋ฐฉ์งํ๋ ค๋ฉด
.gitattributes
์ ํ์ผ์ ๋ช ์์ ์ผ๋ก ์ด์ง ํ์ํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ์์ธํ ๋ด์ฉ์ Git ์ค๋ช ์์ ๊ฒฝ๋ก๋ง๋ค ํน์ฑ ์ ์ - gitattributes๋ฅผ ์ฐธ์กฐํ์ธ์. -
๋ฆฌํฌ์งํ ๋ฆฌ์ ํ์ผ์ ๋ํ ๋ก์ปฌ ๋ณ๊ฒฝ ๋ด์ฉ์ ์์ค์ ๋ฐฉ์งํ๋ ค๋ฉด, ๋ค์ ๋ช ๋ น์ ์คํํ์ฌ ๋ฏธํด๊ฒฐ ๋ณ๊ฒฝ ๋ด์ฉ์ ์ถ๊ฐํ๊ณ ์ปค๋ฐํฉ๋๋ค.
Shell git add . -u git commit -m "Saving files before refreshing line endings"
git add . -u git commit -m "Saving files before refreshing line endings"
-
์ ๊ตฌ์ฑ์ ๋ฐ์ํ๋๋ก ํ์ฌ ๋ถ๊ธฐ์ ๋ชจ๋ ํ์ผ์ ์ ๋ฐ์ดํธํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
Shell git add --renormalize .
git add --renormalize .
-
์ฌ์์ฑ๋ ์ ๊ทํ๋ ํ์ผ์ ํ์ํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
Shell git status
git status
-
ํ์์ ๋ฐ๋ผ ๋ฆฌํฌ์งํ ๋ฆฌ์์ ๋ฏธํด๊ฒฐ ๋ณ๊ฒฝ ๋ด์ฉ์ ์ปค๋ฐํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ ์คํํฉ๋๋ค.
Shell git commit -m "Normalize all the line endings"
git commit -m "Normalize all the line endings"
์ถ๊ฐ ์ฐธ๊ณ ์๋ฃ
- Pro Git ์ค๋ช ์์ Git ์ฌ์ฉ์ ์ง์ - Git ํน์ฑ
- Git ๊ธฐ๋ณธ ํ์ด์ง์ git-config
- Pro Git ์ค๋ช ์์ ์์ - ์ฒซ ๋ฒ์งธ Git ์ค์
- ์ค ๋์ ์ ์(Tim Clem)