2019-06-17 怎么修改老舊的commit message和把多個(gè)commit合并成一個(gè)

[root@VM_0_3_centos project]# git log
commit 895335f40dfbebae3ad933a10f4ab7828885bf41
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 15:35:09 2019 +0800

    add test file

commit 936700dcbe822af203e0b22644353c948b60e52f  #修改message
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:31:36 2019 +0800

    mv readme.txt readme.md

commit 72bf4683bc7f8405f0ab3c976b62abffe4b487b4
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:29:20 2019 +0800

    add readme.txt
[root@VM_0_3_centos project]# git rebase -i 72bf4683bc  #使用此命令,-i指向父提交
r 936700d mv readme.txt readme.md #將pick改為r,并保存退出
pick 895335f add test file

# Rebase 72bf468..895335f onto 72bf468
#
# 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
#
# 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.
#
# Note that empty commits are commented out

Rebasing (1/2)  #保存退出后會(huì)跳到此文件
move readme.txt readme.md  #修改message后,保存退出即可

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# HEAD detached from 72bf468
# You are currently editing a commit while rebasing branch 'master' on '72bf468'.
#
# Changes to be committed:
#   (use "git reset HEAD^1 <file>..." to unstage)
#
#       renamed:    readme.txt -> readme.md
#
[root@VM_0_3_centos project]# git log
commit 93446f01c1d26f60f767d2851bc6f5568ac80179
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 15:35:09 2019 +0800

    add test file

commit 7be55de3dc794d424ef62332d983839bc119f882
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:31:36 2019 +0800

    move readme.txt readme.md   #發(fā)現(xiàn)描述信息已經(jīng)修改

commit 72bf4683bc7f8405f0ab3c976b62abffe4b487b4
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:29:20 2019 +0800

    add readme.txt

多個(gè)commit合并成一個(gè)

[root@VM_0_3_centos project]# git log
commit acc1724d6e26b1771abeabab2356379f7934a4f1
Author: eagle <307509855@qq.com>
Date:   Mon Jun 17 15:03:46 2019 +0800

    add  index.html

commit f91e94a2a1a800047ea2615184ca078113f50bc5
Author: eagle <307509855@qq.com>
Date:   Mon Jun 17 15:02:58 2019 +0800

    add style.css

commit 93446f01c1d26f60f767d2851bc6f5568ac80179
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 15:35:09 2019 +0800

    add test file

commit 7be55de3dc794d424ef62332d983839bc119f882
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:31:36 2019 +0800

    move readme.txt readme.md

commit 72bf4683bc7f8405f0ab3c976b62abffe4b487b4
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:29:20 2019 +0800

[root@VM_0_3_centos project]# git rebase -i 7be55de3   #要合并中間兩次提交
pick 93446f0 add test file
s f91e94a add style.css  #把a(bǔ)dd style.css合并到前一次提交
pick acc1724 add  index.html  #最近一次提交不動(dòng)

# Rebase 7be55de..acc1724 onto 7be55de
#
# 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
#
# 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.
#
# Note that empty commits are commented out

保存退出后跳轉(zhuǎn)到此
# This is a combination of 2 commits.
hebingzhongjianliangge    #增加合并后的message
# The first commit's message is:

add test file

# This is the 2nd commit message:

add style.css

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# HEAD detached at 93446f0
# You are currently editing a commit while rebasing branch 'master' on '7be55de'.
#
# Changes to be committed:
#   (use "git reset HEAD^1 <file>..." to unstage)
#
#       new file:   style.css
#       new file:   test/f1
#
[root@VM_0_3_centos project]# git log  #發(fā)現(xiàn)已經(jīng)合并
commit 58a63bf128c502c65e488b0fd25f7bdd27f84545
Author: eagle <307509855@qq.com>
Date:   Mon Jun 17 15:03:46 2019 +0800

    add  index.html

commit 37c34f5ac9afa9481a2281e6c51d013f237e51d0
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 15:35:09 2019 +0800

    hebingzhongjianliangge
    
    add test file
    
    add style.css

commit 7be55de3dc794d424ef62332d983839bc119f882
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:31:36 2019 +0800

    move readme.txt readme.md

commit 72bf4683bc7f8405f0ab3c976b62abffe4b487b4
Author: eagle <307509855@qq.com>
Date:   Fri Jun 14 14:29:20 2019 +0800

    add readme.txt
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1.說(shuō)明 有時(shí)commit多了看著會(huì)不爽.所以想合并掉一些commit. 這里是最簡(jiǎn)單的情況, 一條線下來(lái)N個(gè)co...
    NowBurn閱讀 3,208評(píng)論 0 0
  • 0. 引言當(dāng)你提交代碼進(jìn)行代碼審查時(shí)或者創(chuàng)建一次pull request (這在開(kāi)源項(xiàng)目中經(jīng)常發(fā)生),你的代碼在被...
    pansly閱讀 47,789評(píng)論 5 9
  • git多個(gè)commit合并 有時(shí)候我們本地寫(xiě)代碼,因?yàn)橐⊥M其他小伙伴的代碼,所以需要先把代碼commit,或...
    Heath閱讀 456評(píng)論 0 1
  • 李文軒 2019-02-24 修改最近一次 commit 的 message: 變基(rebase)命令的特性 變...
    WenxuanLi閱讀 335評(píng)論 0 0
  • 需求 開(kāi)發(fā)過(guò)程,自己的一個(gè)模塊沒(méi)有完成或者有事情走開(kāi)了,不想提交到倉(cāng)庫(kù),但是有恐怕代碼覆蓋或者丟失,就把代碼提交到...
    gzfgeh閱讀 4,902評(píng)論 0 1

友情鏈接更多精彩內(nèi)容