git의 파일 조작(특정 커밋으로 되돌리기, Unstaging 시키기 등)
git restore --staged <file>...
- git restore [file name]을 사용해 특정 파일 HEAD Commit으로 복구하기
- git restore --source [commit hash] [file name] 사용해 특정 파일 특정 Commit으로 복구하기
- git restore --staged [file name] 사용해 Staging Area에 올라간 파일 다시 Unstaging 시키기
git restore [file name]을 사용해 특정 파일 HEAD Commit으로 복구하기
git restore [file name]을 사용하면 특정 파일을 Head Commit으로 복구할 수 있다.
git restore [file name]
예를 들어 다음과 같이 사용 가능하다.
git restore aa.txt
git restore --source [commit hash] [file name] 사용해 특정 파일 특정 Commit으로 복구하기
git restore --source [commit hash] [file name] 을 사용하면 특정 파일을 특정 커밋으로 복구할 수 있다. 이때 --source 옵션은 복구 대상 source(Commit)를 지정하는 것을 뜻한다.
git restore --source [commit hash] [file name]
[commit hash] 자리에는 커밋해시를 나타내는 HEAD 값이 들어갈 수도 있다.
예를 들어 다음과 같이 사용 가능하다.
git restore --source HEAD aa.txt
git restore --source 7abc7def aa.txt
git restore --staged [file name] 사용해 Staging Area에 올라간 파일 다시 Unstaging 시키기
그림1. git restore --staged
git을 조작하다 보면 파일을 잘못 add 할 때가 있다. 이때 add된 파일은 Staging Area로 올라가게 되는데, 이를 다시 Unstaged Area로 옮기기 위한 키워드가 바로 git restore --staged 이다. 우리는 git restore --staged [file name] 을 사용해 특정 파일의 add를 취소할 수 있다.
git restore --staged [file name]
'IT > Git' 카테고리의 다른 글
[Git] Detached Head (0) | 2023.04.11 |
---|---|
[Git] All conflicts fixed but you are still merging. (0) | 2023.03.07 |
[Git] 특정 브랜치 pull / push (0) | 2023.02.28 |
[Git] Fetch와 Pull 차이점 (0) | 2023.02.28 |
[Git] push하지 않은 커밋 확인 (0) | 2023.02.28 |