1. 程式人生 > >git壓縮提交記錄次數

git壓縮提交記錄次數

git 壓縮提交記錄次數

git rebase -i HEAD~n  //n代表你要檢視的提交記錄條數

例如執行

git rebase -i HEAD~4

後會出現:

pick d167a86 提交記錄1
pick c56d2e4 提交記錄2
pick c56d2e4 提交記錄3
pick c56d2e4 提交記錄4
# Rebase 7a28439..c56d2e4 onto 7a28439 (2 commands)
#
# 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 # d, drop = remove commit # # 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

可以看到我們提交的4條記錄,假如,我需要將記錄2、記錄3、記錄4合併到記錄2(只能將最新的合併,即就是 記錄1可以合併記錄2,但是記錄2不能合併記錄1),我們將記錄3、記錄4中的pick改為squash然後儲存更改退出後,然後會進入:

# This is a combination of 3 commits.
# This is the 1st commit message: 提交記錄2 # This is the commit message #2: 提交記錄3 # This is the commit message #3: 提交記錄4 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Fri Oct 12 14:58:12 2018 +0800 # # interactive rebase in progress; onto 7a28439 # Last commands done (2 commands done): # pick d167a86 解決測試中提出的bug,修改etag快取策略 # squash c56d2e4 解決測試中的bug和修改UI佈局,開發新漫畫2.6.0版本 # No commands remaining. # You are currently rebasing branch 'develope' on '7a28439'. # # Changes to be committed: # modified: .gitignore # deleted: .gradle/.DS_Store # deleted: .gradle/2.14.1/.DS_Store # deleted: .gradle/2.14.1/taskArtifacts/cache.properties # deleted: .gradle/2.14.1/taskArtifacts/cache.properties.lock # deleted: .gradle/2.14.1/taskArtifacts/fileHashes.bin # deleted: .gradle/2.14.1/taskArtifacts/fileSnapshots.bin # deleted: .gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin # deleted: .gradle/2.14.1/taskArtifacts/taskArtifacts.bin # deleted: .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin # deleted: .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock # deleted: .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin# deleted: .gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock

我們刪除上面的"提交記錄3、提交記錄4"後,儲存退出,然後執行:

git rebase --continue

執行完畢後會顯示successful資訊。

剛剛申請了一個公眾號,以後準備推送一些好的文章,歡迎你的投稿和關注。 公眾號