Windows 10에 WSL와 Ubuntu를 설치하고 Git & GitHub 환경 설정하기
- WSL 설치
- Ubuntu 설치
$ git --version $ sudo add-apt-repository ppa:git-core/ppa $ sudo apt update $ sudo apt upgrade $ git --version$ git config --global credential.helper "/mnt/c/bin/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"# Git for Windows 2.36.1 부터는 $ git config --global credential.helper "/mnt/c/bin/Git/mingw64/bin/git-credential-manager-core.exe"$ git config --global user.name "Your Name" $ git config --global user.email "[email protected]" $ git config --global init.defaultBranch main $ git config --global pull.rebase true $ git config --global core.editor "code --wait" $ git config --global credential.helper "/mnt/c/bin/Git/mingw64/bin/git-credential-manager-core.exe"설정 확인
$ git config --list --show-origin --show-scope- VS Code as Git editor 를 참고한다.
git config --global core.editor "code --wait"VS Code 를 diff tool로 사용하기
- PowerShell 에서는 다음 커맨드를 사용한다.
git config --global diff.tool default-difftool git config --global difftool."default-difftool".cmd "code --wait --diff `$LOCAL `$REMOTE"- bash 에서는 다음 커맨드를 사용한다.
git config --global diff.tool default-difftool git config --global difftool."default-difftool".cmd "code --wait --diff \$LOCAL \$REMOTE"working directory, index, commit(HEAD) 비교
(1) git diff (a) index <---> (b) working directory (2) git diff <commit> (a) <commit><---> (b) working directory (3) git diff --staged [<commit>] (a) <commit>=HEAD <---> (b) index- (1) working directory 에서 수정한 파일을 index 와 비교한다.
- (2) working directory 에서 수정한 파일을 commit 과 비교한다. 현재 branch 의 가장 최근 commit 과 비교하려면 HEAD 를 지정한다.
- (3) 지정된 commit 과 index 를 비교한다. commit 를 생략하면 기본으로 HEAD 가 지정된다.
두 commit 간의 비교
git diff <commit><commit>git restore [<options>] [--source=<tree>] [--staged] [--worktree] [--] <pathspec>…- 파일을 index에서 working directory로 복사한다.
$ git restore <file>- 파일을 HEAD에서 index로 복사한다.
$ git restore --staged <file>- 파일을 HEAD에서 index와 working directory로 복사한다.
$ git restore --source=HEAD --staged --worktree <file>다음 두 글을 참고한다.
