git commit 合併

  • 平常 git 管理代碼的時候,常常由於由於一些小的代碼改動而進行一次 git commit , 可是這樣形成的後果就是小的 git commit 不少很雜。

  • 今天特地的研究了一些 git commit 的合併方法。

  • 首先,使用 git log 看 log 信息。

root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git log
    commit 93ba40a42595edcbdb5adbab33d8c2dc5409f330
    Author: root <root@aplex.(none)>
    Date:   Mon Nov 13 16:45:55 2017 +0800

        ADD empty directory

    commit 0e35ffa5bdb248464ff2c6587b33206e021d86fc
    Author: root <root@aplex.(none)>
    Date:   Mon Nov 13 16:37:43 2017 +0800

        CMI-AT1010 filesystem init
  • 這裏咱們看到有兩個 git commit , HASH Z值分別爲 93ba40a4259 和 0e35ffa5bdb

  • 這裏,咱們 使用 git rebase -i HEAD~1 進行合併

squash 93ba40a ADD empty directory          # 將要合併的 commit 

    # Rebase 0e35ffa..93ba40a onto 0e35ffa
    #
    # Commands:
    #  p, pick = use commit   使用這個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
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    # However, if you remove everything, the rebase will be aborted.
    #
 
    Init CMI-AT101 filesystem     # commit  message
保存退出
    新的commit  生成
  • 若是操做有誤,能夠使用 git rebase --abort 進行恢復

root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git log
    commit 0e35ffa5bdb248464ff2c6587b33206e021d86fc
    Author: root <root@aplex.(none)>
    Date:   Mon Nov 13 16:37:43 2017 +0800

        CMI-AT1010 filesystem init
    root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git rebase --abort
    root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git log
    commit 93ba40a42595edcbdb5adbab33d8c2dc5409f330
    Author: root <root@aplex.(none)>
    Date:   Mon Nov 13 16:45:55 2017 +0800

        ADD empty directory

    commit 0e35ffa5bdb248464ff2c6587b33206e021d86fc
    Author: root <root@aplex.(none)>
    Date:   Mon Nov 13 16:37:43 2017 +0800

        CMI-AT1010 filesystem init
  • 經驗證,這篇文章有點小問題,讓我有時間再更正一下

相關文章
相關標籤/搜索