git clean
git
쓰는 꼴
git clean -n | git clean -fd추적되지 않은 파일을 지웁니다 — git이 사본을 가진 적이 없어 되살릴 수 없고, -fdx는 .env처럼 무시 목록에 있던 파일까지 지우니 먼저 -n으로 확인합니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| -n | dry run: list what would be deleted |
| -f | actually delete; without it git refuses |
| -d | also remove untracked directories |
| -x | also remove ignored files such as .env and node_modules |
| -X | remove only ignored files |
| -i | decide interactively |
예시
git clean -ndlists the untracked files and folders that -fd would delete
git clean -fddeletes them; git never had a copy, so there is no undo
git clean -fdxalso wipes ignored files, including local .env and build output
되돌리는 방법이 여럿이라 헷갈립니다 — 가리키는 곳을 옮기는 것과 새 커밋을 얹는 것은 다릅니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. git clean은 무엇을 하나요?
추적되지 않은 파일을 지웁니다 — git이 사본을 가진 적이 없어 되살릴 수 없고, -fdx는 .env처럼 무시 목록에 있던 파일까지 지우니 먼저 -n으로 확인합니다.
Q. 어떻게 치나요?
git clean -n | git clean -fd — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 6개입니다. 전체 목록은 man git에 있습니다. 이 명령은 git 갈래입니다.
같이 보는 명령
man 페이지: man git-clean