기본적으로 checkout
이 구명령어이고 대부분의 작업을 수행가능.
switch
와 restore
는 신규명령어로 checkout
의 기능을
양분한다고 보면됨.
<file-name>
git checkout HEAD <file-name>
나 git checkout -- <file-name>
과 동일하다고 보면됨.
<file-name>
file의 상태를 n commit 전으로 돌려보냄. 단 head의 위치는 변하지않음.
git restore <file-name>
으로 파일을 원상복구 가능.
veritas@veritas:~/gitserver/gittest$ git status
On branch master
nothing to commit, working tree clean
veritas@veritas:~/gitserver/gittest$ git restore --source HEAD~2 a.py
veritas@veritas:~/gitserver/gittest$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a.py
no changes added to commit (use "git add" and/or "git commit -a")
veritas@veritas:~/gitserver/gittest$ git log --oneline
0832b08 (HEAD -> master) change
9604190 modified merge
3085d7f (dev1) change2
c89332b change1
07e0d34 init2
6793199 init
veritas@veritas:~/gitserver/gittest$ git restore a.py
veritas@veritas:~/gitserver/gittest$ git status
On branch master
nothing to commit, working tree clean
<file-name>
git restore <file-name>
가 unstaged (git add 되기전) 파일을 원상복구 시킨다면 --staged 옵션을 통해 staged(git add/tracked된) 파일을 원상복구 시킨다고 보면됨.
veritas@veritas:~/gitserver/gittest$ git status
On branch master
nothing to commit, working tree clean
veritas@veritas:~/gitserver/gittest$ vim a.py
veritas@veritas:~/gitserver/gittest$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a.py
no changes added to commit (use "git add" and/or "git commit -a")
veritas@veritas:~/gitserver/gittest$ git add .
veritas@veritas:~/gitserver/gittest$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: a.py
veritas@veritas:~/gitserver/gittest$ git restore --staged a.py
veritas@veritas:~/gitserver/gittest$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a.py
no changes added to commit (use "git add" and/or "git commit -a")
veritas@veritas:~/gitserver/gittest$ git restore a.py
veritas@veritas:~/gitserver/gittest$ git status
On branch master
nothing to commit, working tree clean