Dev/Git
Git 간단한 사용법 - commit --amend
Itips
2019. 6. 21. 06:42
반응형
작업을 마치고 commit 까지 완료했는데 추가 작업이 생겨서 바로 전 커밋에 같이 포함시켜야 할 경우가 종종 있다.
이 때 필요한 Git 명령 그리고 옵션이 바로 commit --amend 이다. 아래 코드 참조.
먼저 최초 수정한 작업이 아래와 같이 있다고 가정한다.
[~/test/local] (master) $ echo 'new changes' > index.html
[~/test/local] (master) $ git add index.html
[~/test/local] (master) $ git commit -m "first change"
[master (root-commit) 5ac076a] first change
1 file changed, 1 insertion(+)
create mode 100644 index.html
[~/test/local] (master) $ git log --oneline
5ac076a (HEAD -> master) first change
커밋 5ac076a 이 생성되었다. 이제 기존 파일을 수정하고 커밋할 준비를 한다.
[~/test/local] (master) $ echo 'additional changes' >> index.html
[~/test/local] (master) git add index.html
[~/test/local] (master) git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: index.html
아래 명령어를 실행하면 마지막으로 만들었던 커밋 5ac076a 의 메세지 등록 하면이 나온다. 내용을 수정 후 ':wq" 로 변경내용을 저장하고 나온다.
[~/test/local] (master) $ git commit --amend
[master 432090a] first change has been changed twice
Date: Thu Jun 27 14:03:08 2019 +1000
1 file changed, 2 insertions(+)
create mode 100644 index.html
커밋 히스토리를 보면 커밋 5ac076a 이 사라지고 신규 커밋 432090a 이 생성되어 있음을 확인할 수 있다.
[~/test/local] (master) $ git log --oneline
432090a (HEAD -> master) first change has been changed twice
[~/test/local] (master) $ git status
On branch master
Your branch is based on 'origin/master', but the upstream is gone.
(use "git branch --unset-upstream" to fixup)
nothing to commit, working tree clean
신규 생성된 커밋 내역을 보면 추가로 변경한 내용이 기존의 커밋에 더해져 있다.
[~/test/local] (master) $ git show 432090a
commit 432090a409d29eaa164a9455d87379727081ce31
Author: Wangsung Kim <brkim@redhat.com>
Date: Thu Jun 27 14:03:08 2019 +1000
first change has been changed twice
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..3e8c755
--- /dev/null
+++ b/index.html
@@ -0,0 +1,2 @@
+new changes
+additional changes
반응형