# This is a combination of 12 commits. # This is the 1st commit message:
Add'H'to squash.txt
# This is the commit message #2:
Add'e'to squash.txt
# This is the commit message #3:
Add'l'to squash.txt
# This is the commit message #4:
Add'l'to squash.txt
# This is the commit message #5:
Add'o'to squash.txt
# This is the commit message #6:
Add','to squash.txt
# This is the commit message #7:
Add' 'to squash.txt
# This is the commit message #8:
Add'w'to squash.txt
# This is the commit message #9:
Add'o'to squash.txt
# This is the commit message #10:
Add'r'to squash.txt
# This is the commit message #11:
Add'l'to squash.txt
# This is the commit message #12:
Add'd'to squash.txt
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Sun Apr 28 14:21:56 2019 -0400 # # interactive rebase in progress; onto 1af1b46 # Last commands done (12 commands done): # squash a513fd1 Add 'l' to squash.txt # squash 6b608ae Add 'd' to squash.txt # No commands remaining. # You are currently rebasing branch 'squash' on '1af1b46'. # # Changes to be committed: # new file: squash.txt #
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Sun Apr 28 14:21:56 2019 -0400 # # interactive rebase in progress; onto 1af1b46 # Last commands done (12 commands done): # squash a513fd1 Add 'l' to squash.txt # squash 6b608ae Add 'd' to squash.txt # No commands remaining. # You are currently rebasing branch 'squash' on '1af1b46'. # # Changes to be committed: # new file: squash.txt #
第一步是启动交互式变基。让我们用 git rebase -i HEAD~2 来变基这两个提交,给出的变基计划如下:
1 2 3 4 5 6 7 8
index_imgk 237b246 Add C program skeleton index_imgk b3f188b Flesh out C program
# Rebase c785f47..b3f188b onto c785f47 (2 commands) # # Commands: # p, index_imgk <commit> = use commit # e, edit <commit> = use commit, but stop for amending
Last commands done (2 commands done): index_imgk 237b246 Add C program skeleton edit b3f188b Flesh out C program No commands remaining. You are currently splitting a commit while rebasing branch 'master' on 'c785f47'. (Once your working directoryis clean, run "git rebase --continue")
Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)
modified: main.c
no changes added to commit (use "git add"and/or"git commit -a")
这个大块看起来更好:单一、独立的更改。让我们按 y 来回答问题(并暂存那个“大块”),然后按 q 以“退出”交互式会话并继续进行提交。会弹出编辑器,要求输入合适的提交消息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Add get_name function to C program
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # interactive rebase in progress; onto c785f47 # Last commands done (2 commands done): # index_imgk 237b246 Add C program skeleton # edit b3f188b Flesh out C program # No commands remaining. # You are currently splitting a commit while rebasing branch 'master' on 'c785f47'. # # Changes to be committed: # modified: main.c # # Changes not staged for commit: # modified: main.c #
# Rebase fe19cc3..f03baa5 onto fe19cc3 (3 commands) # # Commands: # p, index_imgk <commit> = use commit # # These lines can be re-ordered; they are executed from top to bottom.