git rebase -i aaaa6666 # aaaa6666为所修改commit的 父亲commit 的hash值
###得到以下交互信息: pick 17eeb4a change index ###将要修改的massage,pick改为r pick 3c052e5 move readme.md to readmine + Add readme ###不需修改的massage,保持 pick pick 0abe5ee rm rqeq1 ###不需修改的massage,保持 pick # Rebase e7d6113..0abe5ee onto aaaa6666 (3 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>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted.
随后跳出的页面就是修改 massage。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
change index ### 修改成自己想要的 massage
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: ... # # interactive rebase in progress; onto aaaa6666 # Last commands done (1 commands done): # reword e7d6113 ... # Next command to do (0 remaining command): # You are currently editing a commit while rebasing branch 'master' on 'aaaa6666'. # # Changes to be committed: # modified: ...
git rebase -i aaaa6666 #aaaa6666为合并的四个commit的 父亲commit 的hash值
###1.要合并前三条commit pick d93a5a2 Add images+index #----必须保留一条pick s e7d6113 add inin #----pick改为s s 17eeb4a change index #----pick改为s pick 3c052e5 move readme.md to readmine + Add readme pick 634bfa3 rm rqeq1+2 # # 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>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # You are editing the todo file of an ongoing interactive rebase. -- INSERT --
###2.添加合并的massage # This is a combination of 3 commits. #----在此处添加massage # This is the 1st commit message:
Add images+index
# This is the commit message #2:
add inin
# This is the commit message #3:
change index
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Sat Mar 7 20:32:23 2020 +0800 # # interactive rebase in progress; onto cef862a # Last commands done (3 commands done): # squash e7d6113 add inin # squash 17eeb4a change index # Next commands to do (2 remaining commands): # pick 3c052e5 move readme.md to readmine + Add readme # pick 634bfa3 rm rqeq1+2 # You are currently rebasing branch 'master' on 'cef862a'. # -- INSERT --
(4)多个间隔的commit合并成一个
找到最老旧的 commit 的 parents
手动在最上面添加 pick parents_hash
将要合并的 commit 剪切到 pick parents_hash 下面,并将 pick 改成 s
diff --git a/f1 b/f1 # 对比 a 版本的 f1 和 b 版本的 f1 index 6f8a38c..449b072 100644 # a 版本的 f1 和 b 版本的 f1 各自的哈希值 --- a/f1 # --- 表示改动前的版本 +++ b/f1 # +++ 表示改动后的版本,并不一定是改动后的文件增加了代码。 @@ -1,7 +1,7 @@ # -1,7 表示改动前的文件,从第 1 行开始 7 行发生了改动/产生了影响; # +1,7 表示改动后的文件,从第 1 行开始 7 行发生了改动/产生了影响; a a a -a +b a a a
10.git文件夹内容
1 2 3 4
cat HEAD #当前所在分支,是个引用,指向了refs/heads中当前所在分支 cat config #配置文件 cd refs/tags #标签 cd refs/heads #版本库(哈希值)
###创建一个没有分支的工作区,注意:当切换到其他分支时,此工作区将被当作垃圾丢弃,此处会产生以下提醒: ➜ use_git git:(a0a5992) git checkout master Warning: you are leaving 2 commits behind, not connected to any of your branches:
a0a5992 2.txt 35f7cdf 1.txt
If you want to keep them by creating a new branch, this may be a good time to do so with: