해당 문서를 정확하기 위해서는 Git의 상태 변화와 스테이지 영역에 대한 이해가 필요하니, 관련된 참고자료를 먼저 확인해주시면 좋겠습니다.
git reset은 특정 커밋으로 돌아가거나, 스테이징된변경 사항을 초기화하는데 사용하는 명령어 입니다. 즉 현재 상태에서 선택한 이전 커밋 상태로 변경사항을 되돌리는 것입니다.
Git을 사용하다 보면 다음과 같은 이유 등으로 HEAD의 위치를 옮겨서 과거 커밋 상태로 되돌리거나 작업 내용을 수정하고 싶을 때가 있습니다.
이를 위해 git reset 명령어를 사용합니다.
git reset을 제대로 사용하려면, 함께 사용할 수 있는 다양한 옵션들을 정확히 이해해야 합니다.
현재 우리는 feature 브랜치에서 작업 중이며, 두 개의 커밋을 만든 상태입니다. 그 상태를 먼저 확인해보겠습니다.
$> git log --oneline
a1b2c3d (HEAD -> feature) Second commit
f6g7h8i First commit
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome to my page!</h1>
<p>This is the second version of my page.</p> <!-- 추가된 내용 -->
</body>
</html>
--soft 옵션:
$> git reset --soft HEAD~1
Changes to be committed:
modified: index.html
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome to my page!</h1>
<p>This is the second version of my page.</p> <!-- 추가된 내용 -->
</body>
</html>
$> git reset --mixed HEAD~1
$> git status
Changes not staged for commit:
modified: index.html
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome to my page!</h1>
<p>This is the second version of my page.</p> <!-- 추가된 내용 -->
</body>
</html>
$> git reset --hard HEAD~1
$> git status
nothing to commit, working tree clean
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome to my page!</h1>
</body>
</html>
MSA는 정말 훌륭한 아키텍처인가? (0) | 2025.02.22 |
---|---|
Discord가 웹소켓 트래픽을 40% 감소시킨 방법 (0) | 2024.09.29 |
Spring MVC 아키텍처 개요 (2) | 2024.09.19 |
구조패턴중, Proxy 패턴에 대하여.. (2) | 2024.09.17 |
구조패턴 중, 어댑터(Adapter)패턴에 대하여... (0) | 2024.07.14 |
댓글 영역