프로그래밍/Git, Github
[Git | CLI] 로컬에서 변경 파일을 되돌리는 명령어
blueprint-12
2023. 7. 2. 21:13
찾게된 이유:
- checkout 을 할 때, 변경사항이 있다면 다른 브랜치로 체크아웃이 안된다.
- 또한, 해당 브랜치에 내 로컬의 변경 사항을 commit하려고 할 때, 원격저장소(gitHub)에 변경사항이 있다면 pull을 한 뒤, commit 해야 한다. => 사실 이 경우에는 그냥 pull 한 뒤, 내 파일들과 같이 commit하면 된다. (커밋과 풀의 순서만 바뀐 것뿐)
- 위와 같은 상황에서 아예 변경사항을 원래 상태로 되돌리고 싶을 때 아래의 명령어를 사용해주면 된다. 나는 restore . 명령어를 통해서 기존에 작업했던 것들을 모두 이전 상태로 되돌린 다음 pull 명령어를 실행시켜주었다. (이유: css 작업하다가 결국 내가 원하는 모양이 안나와서 변경파일들을 그냥 다 이전상태로 되돌리고 싶었다..)
To revert changes made to your working copy, do this:
git checkout .
Or equivalently, for git version >= 2.23:
- 위의 명령어와 동일하지만 git 버전에 2.23이상일 경우, `restore .` (모든 변경사항이 있는 파일들을 되돌린다라는 의미인듯)
git restore .
To revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:
git reset
To revert a change that you have committed:
git revert <commit 1> <commit 2>
To remove untracked files (e.g., new files, generated files):
git clean -f
Or untracked directories (e.g., new or automatically generated directories):
git clean -fd
all ref: 스택오버플로우 "how do I revert all local changes"