Git이란?
버전을 편리하게 관리할 수 있도록 도와주는 대중적이고 전문적인 도구
e.g. 우리가 타임머신을 타고 원하는 순간으로 가고 싶은 것처럼, 우리가 작업하고 있는 파일들을 원하는 순간으로 다시 돌아갈 수 있게 만들어주는 도구
깃 사용방법
- Terminal: Original Git - Command based program (Mac: iterm, Windows: cmder 추천!)
- GUI Application
- Source Tree: 대중적인 도구
- Github desktop: 기능 많이 없음
- Git kraken: 멋진 UI
깃 기본 명령어 (Windows Terminal)
- git – version: 깃 버전확인
- git config – list: 깃 설정 확인
초기설정
- .gitconfig 파일: 모든 환경설정
- git config – global core.editor “code [–wait]”: Text Editor로 연결해서 Git을 사용하는것도 가능
- git config –global user.name “username”
- git config –global user.email “email@example.com”
- git config –global core.autocrlf true
- Text editor에서 Windows에서는 text \r\n (line feed) 동시에 들어감, Mac에서는 text\n (line feed) 만 들어감. (\r = carriage return)
- 다양한 운영체제에서 git 사용시 git history에 보는데 문제가 생길 수 있음
- 맥도 따로 처리 해주는 이유는 이메일에서 내용 복사해올 시에 \r이 자동으로 들어갈 수도 있음
깃 초기화/삭제하기
- mkdir git
- git init: git project 시작
- rm -rf .git: git project 삭제
- git status: git status check
- git config –global alias.”shorthand” “command”: shorthand type command configuration
- git config –h: command helper
Git working flow (file status)
- Working directory: file modifying, working space
- Untracked
- Tracked: Tracked by version history(commit)
- Unmodified:
- Modified: Allow to ‘add’ to staging area
- Staging area: files get ready to commit version history
- .git directory: git version history record
- Local repository: My computer
- Remote repository: github server
- Tip. Commit components
git add
- How to commit
- git add “filename.type”: add to staging area
- Untracked files or tracked&modified files
- How to remove commit(or add)
- git rm –cashed “filename”
- E.g. If a.txt has been added to staging area with git add * and deleted in working area. the result of git status is including a.txt. However, if we use git add . after the file is deleted, the deleted file is removed from the staging area.
git ignore: tracking 하고 싶지 않은 파일(e.g. log)
- .gitignore 숨겨진 파일 생성 후 텍스트 파일에 commit하고 싶지않은 파일들 제목을 올린다.
- echo *.log > .gitignore => add 가능한 목록에서 사라짐
- gitignore 파일안에 특정 디렉토리 or 특정 format을 가진 파일들을 넣어서 제외시킬 수 있음.
git status: 작업사항 간단히 확인
- git status –long:
- git status –s: A (add), ??: working directory untracked
- git status –[option]:
git diff: working directory에서 변경사항
- command cat command: 파일 내용 확인
- git diff –staged(or –cached):
- git difftool: tool을 이용하여 git diff 조회 (git config –global -e를 통해 editor를 설정후 사용 가능)
First commit
- 구성
- Git log:git log 확인
- Git add . 후 git commit 후 vscode 이용하여 Title, description 추가 후 닫으면 자동으로 commit
- 파일 수정 후 git add . 후 git commit -m “commit name” 입력하면 따로 vscode 실행하지 않고 바로 commit 가능 (-m [message option])
Git commit 팁
- 규모?
- History에는 작은 단위로 나눠서 저장하는게 좋음
- 현재, 동사원형으로
- 각 commit에 해당되는 내용만 포함할 것
- E.g. initialize project, add loginservice module, => 의미있는 청크 덩어리로 작업한 내용 commit할 것
Source
2020-11-17 깃, 깃허브 제대로 배우기 - 드림코딩 by 엘리