commit
- 작업 중간중간 세이브 포인트 느낌.
- 중요함.
- 그래서 commit에 대해 조작하는걸 조금 더 보기로 함.
- 이 전까지 commit만들고, 그 commit 중 어떤 시점으로의 이동을 하는 방법을 봤다.
이번엔 그 외 할 수 있는것들을 써보자. - 이게 기본
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ cat contents/contents.md 1 2 3 4 5 psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git log --oneline 2a87176 (HEAD -> contents_1, origin/contents_1, origin/contents, contents) 5 4a123de 4 130976b 3 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit
rebase
- commit에 대한 제어(?)를 할 때 씀
- 제어가 정확한 표현이 될지 모르겠는데 commit message 수정, 병합, 분할, 제거, 해당 commit 작업내용의 수정 등
- git rebase -i –root로 시작
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git rebase -i --root pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 pick 130976b 3 pick 4a123de 4 pick 2a87176 5 # Rebase 2a87176 onto 24f8565 (7 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]lo0 # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was
- git rebase -i –root
- -i는 –interective로 … 상호작용? 대화형이라는데 ..잘 모르겠.. 그냥 이거 쓰래
- –root는 root가 되는 commit부터 보겠다는 뜻
이전 다른 것들처럼 HEAD~3등 할 수 있는데 HEAD를 움직인 경우 그 다음 commit부터 수정가능. - 대충 이렇게 알고있는데 시작할때 –root 쳐서 했던거로 기억함.
- pick : commit를 사용하겠다함. 근데 기본으로 다 pick되어있고.. 무슨의미인지 모르겠음
- reword : commit message수정
- edit : commit message수정, 근데 commit 작업 내용 수정도 가능
- squash : 이전 commit 에 합침..
- fixup : squash와 같은데 message는 무시함
- exec : 그냥 cmd 실행인듯?
- break : rebase 일시정지
- drop : commit 지움
- label :
- reset : HEAD를 labal로
- merge : commit merge
- 내용은 pick부분을 수정한다.
- 할 수 있는건 해보기로.
- git rebase -i –root
reword, edit
- reword는 commit 수정
edit는 commit 수정, 실제 내용 수정도 가능reword
- 4의 commit message 를 수정해봄
- 수정 할 commit 지정
1 2 3 4 5 6 7
pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 pick 130976b 3 reword 4a123de 4 pick 2a87176 5
- 에디터에서 수정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
4 - reword # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Author: psy_comp <psy0231@gmail.com> # Date: Fri Aug 7 14:08:04 2020 +0900 # # interactive rebase in progress; onto 9993e1b # Last commands done (6 commands done): # pick 130976b 3 # reword dd097ac 4 - reword # Next command to do (1 remaining command): # pick 9ec22fd 5 # You are currently editing a commit while rebasing branch 'contents_1' on '9993e1b'. # # Changes to be committed: # modified: contents/contents.md
- 확인
1 2 3 4 5 6 7 8 9
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git log --oneline 7293f2b (HEAD -> contents_1) 5 3fe0ebb 4 - reword 130976b 3 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit
- 별거 없이 바뀌는데 처음과 다른점은 reword한 4 commit을 포함한 그 이후 commit가 id가 다 바뀜.
- 참고로, 맨 마지막 commit message만 수정하는경우 git commit –amend로 하면 간단함
edit
- 3 commit 내용 및 commit message 수정
1 2 3 4 5 6 7
pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 edit 130976b 3 pick 3fe0ebb 4 - reword pick 7293f2b 5
- reword랑 다른점
- 상태가 바뀜. 또 실제 그 당시 내용으로 돌아감
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ git rebase -i --root Stopped at 130976b... 3 You can amend the commit now, with git commit --amend Once you are satisfied with your changes run git rebase --continue psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2|REBASE 5/7) $ psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2|REBASE 5/7) $ git status interactive rebase in progress; onto b74e4ed Last commands done (5 commands done): pick 24f8565 2 edit 130976b 3 (see more in file .git/rebase-merge/done) Next commands to do (2 remaining commands): pick 3fe0ebb 4 - reword pick 7293f2b 5 (use "git rebase --edit-todo" to view and edit) You are currently editing a commit while rebasing branch 'contents_2' on 'b74e4ed'. (use "git commit --amend" to amend the current commit) (use "git rebase --continue" once you are satisfied with your changes) nothing to commit, working tree clean psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2|REBASE 5/7) $ cat .git/ contents/ README.md psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2|REBASE 5/7) $ cat contents/contents.md 1 2 3
- 상태가 바뀜. 또 실제 그 당시 내용으로 돌아감
- 여기부터 수정 가능해짐.
- 내용수정
1 2 3
1 2 3 - fix
- git add .
- git rebase –continue
- 이때 해당 commit 의 commit message를 수정할수 있음.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
3 - commit message fix # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Author: psy_comp <psy0231@gmail.com> # Date: Fri Aug 7 14:07:48 2020 +0900 # # interactive rebase in progress; onto 8c3afc4 # Last commands done (5 commands done): # pick 24f8565 2 # edit 130976b 3 # Next commands to do (2 remaining commands): # pick 3fe0ebb 4 - reword # pick 7293f2b 5 # You are currently splitting a commit while rebasing branch 'contents_2' on '8c3afc4'. # # Changes to be committed: # modified: contents/contents.md
- 이때 해당 commit 의 commit message를 수정할수 있음.
- conflict 해결.
- 여기부터 뒤로 전부 걸리는것같음.ㄷㄷ
- 매번 commit 수정하고 2,3,4를 끝까지 반복
- 내용수정
- 확인
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ git log --oneline 13e1946 (HEAD -> contents_2) 5 abf82d6 4 - reword 7635b6a 3 - commit message fix 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ cat contents/contents.md 1 2 3 - fix 4 5
- reword처럼 commit id가 다 바뀜
- 혹시나해서.. 붙어있는 commit 를 분할할때 이걸쓰면 됨
근데 commit분할은 이거 말고도 다른 방법이 많이보이긴 한데 일단 말나온김에 써봄- 아래 예시에서 3,4를 따로 분리하고자함
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ git log --oneline 1afb93f (HEAD -> contents_2, contents_1) 5 f5afcaa 3 and 4 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ cat contents/contents.md 1 2 3 4 5
- edit로 진입, 마지막 commit로 돌아옴
1 2 3 4 5 6 7 8 9 10 11 12 13 14
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 edit f5afcaa 3 and 4 pick 1afb93f 5 psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2|REBASE 5/6) $ cat contents/contents.md 1 2 3 4
마지막 commit에 있어야할 내용으로 수정 후
git add .
git commit –amend
여기서는 4를 지우고 commit message로 3으로 바꿈git rebase –continue로 진행하면 이 후 commit가 들어오는데
이걸 쓰지말고 4를 만들어야함
위 까지 하면 1,2,3까지 만들어진상태. 아래 4를 넣고
add , commit -m “4”- 다음 5를 만들고 add, commit -m “5”
git rebase –continue로 끝냄1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ git log --oneline 31f0cee (HEAD -> contents_2) 5' 7df1f7c 4' 4b86f26 3' 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_2) $ cat contents/contents.md 1 2 3 4 5
- 이렇게 되면 하나였던 commit를 분리가 된건데 하다보니 좀 안좋은것같아서 branch 할때 이거랑 섞어 다시 쓰겠음
- 아래 예시에서 3,4를 따로 분리하고자함
squash, fixup
- squash는 현재 commit를 이 전 commit를 합침
fixup는 squash같이 단, 해당 commit 무시 - 각각 5를 4에 squash, 3을 2에 fixup 해봄
squash
- 5를 4에 squash 하면
1 2 3 4 5 6 7
pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 pick 130976b 3 pick 4a123de 4 squash 2a87176 5
- commit를 수정하는 에디터가 뜸. squash는 commit message를 버리지 않고 수정 가능하게 해줌
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# This is a combination of 2 commits. # This is the 1st commit message: 4 # This is the commit message #2: 5 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Author: psy_comp <psy0231@gmail.com> # Date: Fri Aug 7 14:08:04 2020 +0900 # # interactive rebase in progress; onto 17834a7 # Last commands done (7 commands done): # pick 4a123de 4 # squash 2a87176 5 # No commands remaining. # You are currently rebasing branch 'contents_1' on '17834a7'. # # Changes to be committed: # modified: contents/contents.md
- 잘 수정하고 저장하면 결과 보여줌
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git rebase -i --root [detached HEAD 99b7318] 4 and 5 Author: psy_comp <psy0231@gmail.com> Date: Fri Aug 7 14:08:04 2020 +0900 1 file changed, 3 insertions(+), 1 deletion(-) Successfully rebased and updated refs/heads/contents_1. psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git log --oneline 99b7318 (HEAD -> contents_1) 4 and 5 130976b 3 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit
fixup
- 3을2에 fixup해봄 (위꺼에 이어)
1 2 3 4 5 6
pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 fixup 130976b 3 pick 99b7318 4 and 5
- squash와 다르게 이건 선택된 로그를 쓰지 않으므로 바로 끝남
1 2 3 4 5 6 7 8 9 10 11
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git rebase -i --root Successfully rebased and updated refs/heads/contents_1. psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git log --oneline 111bcf4 (HEAD -> contents_1) 4 and 5 7618668 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit
squash, fixup??
- 일단, 결과는 commit가 합쳐지는 것으로 같음. 다른점은 commit를 다시 쓰냐 마냐정도
단, 둘다 결과 commit부터 그 뒤 commit id가 다 바뀜. - 결과에 대해 조금 더 보면
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git diff 3aa9de8..7618668 diff --git a/contents/contents.md b/contents/contents.md index 56a6051..5f5fbe7 100644 --- a/contents/contents.md +++ b/contents/contents.md @@ -1 +1,3 @@ -1 \ No newline at end of file +1 +2 +3 \ No newline at end of file psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git diff 7618668..111bcf4 diff --git a/contents/contents.md b/contents/contents.md index 5f5fbe7..85954ea 100644 --- a/contents/contents.md +++ b/contents/contents.md @@ -1,3 +1,5 @@ 1 2 -3 \ No newline at end of file +3 +4 +5 \ No newline at end of file psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $
- 1 commit 에서 2 commit로 넘어갈 때 보면 2,3 동시애 함. 여기서 4,5로 넘어갈때도 마찬가지.
- 다시말해 합쳐진 두 commit는 두 commit의 실제 작업내용을 갖고있음
- 걍 자잘한 commmit 지울때 좋은듯.
exec
- run cmd라는데
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
pick 73fd2f2 Initial commit pick a693728 contents init exec cat contents/contents.md pick 3aa9de8 1 exec cat contents/contents.md pick 24f8565 2 exec cat contents/contents.md pick 130976b 3 exec cat contents/contents.md pick 4a123de 4 exec cat contents/contents.md pick 2a87176 5 psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git rebase -i --root Executing: cat contents/contents.md Executing: cat contents/contents.md Executing: cat contents/contents.md 1 Executing: cat contents/contents.md 1 2 Executing: cat contents/contents.md 1 2 3 Successfully rebased and updated refs/heads/contents_1.
- 이런식인데 잘 모르겠음 저렇게 쓰는것도 맞나싶고..
중간부터 왜 안되는지 모르겠음
drop
- commit 삭제
1 2 3 4 5 6 7
pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 pick 130976b 3 pick 4a123de 4 drop 2a87176 5
- 바로 끝나는데
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git rebase -i --root Successfully rebased and updated refs/heads/contents_1. psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ git log --oneline 4a123de (HEAD -> contents_1) 4 130976b 3 24f8565 2 3aa9de8 1 a693728 contents init 73fd2f2 (origin/master, origin/HEAD, master) Initial commit psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test (contents_1) $ cat contents/contents.md 1 2 3 4
- 내용, commit 다 지워지는건가봄
- 중간꺼 하나더.
1 2 3 4 5 6 7
pick 73fd2f2 Initial commit pick a693728 contents init pick 3aa9de8 1 pick 24f8565 2 drop 130976b 3 pick 4a123de 4 pick 2a87176 5
- 이상태에서는 conflict남
- edit할 때 처럼 다 수정해줘야함.
- 또, drop쓸 줄을 그냥 지워도 똑같이 동작한다함.
label, reset, merge
- ??
Comments powered by Disqus.