Git 기본 안내
설치
- Arch Linux
- Debian
sudo pacman -S git
sudo apt install git
git config --global user.name "Hyeonki Hong"
git config --global user.email "[email protected]"
- 회사 아이디, 개인 아이디 등 여러 email을 사용하는 경우
--global
대신 각 리포지토리에서--local
옵션으로 설정하면 됩니다.
git config --global core.autocrlf input \
&& git config --global core.eol lf \
&& git config --global core.editor vim \
&& git config --global core.ignorecase false
- Linux
- macOS
git config --global credential.helper 'cache --timeout=86400'
git config --global credential.helper osxkeychain
clone
git clone <repository>
git clone <repository> -b <tag or branch> --single-branch
git clone <repository> -b <tag or branch> --depth <# of commit>
add, rm, mv, commit

add
git add
명령어는 Untracked file, Modified file 을 Staging area에 반영합니다.
git add <file>
git add .
rm
git rm
명령어는 Tracked file을 Untracked file로 변경하고 Staging area에 삭제된 상태라는 것을 반영합니다.
git rm <file>
파일이 변경되어 Staging area에 있는 경우 -f 옵션을 사용해 강제 삭제 해야합니다.
git rm -f <file>
mv
git mv
명령어는 파일의 위치를 변경하거나 이름을 변경을 한 후 Staging area에 반영합니다.
git mv <file> <newName|directory>
commit
git commit
명령어는 Staging area에서 파일을 제외시키고, Unmodified file로 변경한 후 commit된 하나의 작업으로 등록합니다.
git commit
git commit -m "<message>"
log
log with commit message
git log [-<# of commit>] [directory or file]
log with commit message + diff
git log -p [-<# of commit>] [directory or file]
log with commit message + statistic
git log --stat [-# of commit] [directory or file]
log with oneline commit message
git log --oneline [--graph] [-# of commit] [directory or file]
git log --pretty=format:"[format]" [--graph] [-# of commit] [directory or file]
reflog
git reflog
명령어로 git 변경 이력을 확인할 수 있습니다.
git reflog