3개의 커밋을 하나로 합쳐본다.



$ git log --pretty=oneline

aae3f8afa5c7e97d8974525994f100b93258baf3 commit 3

2c24df186d7b779a87882e0968503fb019866d62 commit 2

ae08eead7cf187b85fd73d5a2ceb3f0a256c99b1 commit 1


3번 commit/push했고 이를 하나의 commit 메시지로 만들고 싶을 때 사용할 수 있는 git 커맨드를 소개한다. 



최신 3개의 commit을 rebase로 하나로 합쳐 본다. -i는 대화형 모드를 의미한다. 


$ git rebase -i HEAD~3

  

pick ae08eea commit 1

pick 2c24df1 commit 2

pick aae3f8a commit 3


# Rebase acf9816..aae3f8a onto acf9816 (3 command(s))

#

# Commands:

# p, pick = use commit

# r, reword = use commit, but edit the commit message

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

# f, fixup = like "squash", but discard this commit's log message

# x, exec = run command (the rest of the line) using shell

# d, drop = remove commit

#




아래와 같이 수정한다. 

commit 1은 그대로. commit 2와 commit 3의 pick을 squash또는 s로 변경한다. 


pick ae08eea commit 1

squash 2c24df1 commit 2

squash aae3f8a commit 3


# Rebase acf9816..aae3f8a onto acf9816 (3 command(s))

#

# Commands:

# p, pick = use commit

# r, reword = use commit, but edit the commit message

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

# f, fixup = like "squash", but discard this commit's log message

# x, exec = run command (the rest of the line) using shell

# d, drop = remove commit

#


저장하고 종료하면 squash 화면이 나타난다. 

여기에서 commit1 앞에 REDIS-1을 추가해본다. 


다음 화면이 나타나고 쉘로 나온다. 



 3 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 1

 create mode 100644 2

 create mode 100644 3

Successfully rebased and updated refs/heads/master.



3개의 commit이 하나의 commit으로 나타난다. 


$ git log --pretty=oneline

7dca124e20dea4a4248be52eae50081580ac329d REDIS-1 commit 1

acf9816e316d960df3a99c6bb9c0ee40ac31dee0 Initial commit



해당 commit을 확인해보면 commit 1, commit 2, commit 3 모두 존재한다.


$ git log -p 1

commit 7dca124e20dea4a4248be52eae50081580ac329d

Author: knight76@gmail.com

Date:   Tue Oct 24 19:27:43 2017 +0900


    REDIS-1 commit 1


    commit 2


    commit 3


diff --git a/1 b/1

new file mode 100644

index 0000000..e69de29




이미 remote repository에 저장했기 때문에 git push --force를 실행해서 서버에도 반영한다.






만약, push를 하지 않은 상태라면 git reset --soft HEAD~3 커맨드를 사용하면 된다. 



$ git log --pretty=oneline

13a9d0da6ebf8f0ab2d78761cd26bad3136c5cec commit 3

628a2b89c35e134aeccd0e26dc90dc78575f2493 commit 2

e8630d725e97f8f11e8036d303abe4812f956dea commit 1

acf9816e316d960df3a99c6bb9c0ee40ac31dee0 Initial commit


$ git reset --soft HEAD~3


$ git status

On branch master

Your branch is up-to-date with 'origin/master'.

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)


new file:   1

new file:   2

new file:   3


$ git log --pretty=oneline

acf9816e316d960df3a99c6bb9c0ee40ac31dee0 Initial commit


$ git add .

$ git commit -m 'REDIS-1 commit 1'

[master a3eaa44] REDIS-1 commit 1

 3 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 1

 create mode 100644 2

 create mode 100644 3

$ git push


Posted by '김용환'
,