1. 程式人生 > 其它 >Git修改以前某次歷史提交註釋

Git修改以前某次歷史提交註釋

比如Git的提交記錄是這樣的:

$ git log
b536e0c Smart Linux:enable adbd
bd45a6f Smart Linux:optimize Audio driver and auto load
e14fcfa Smart Linux:load fw issue
6d5aca7 Smart:add bootimage target #這一次提交少了一個Linux,強迫症看著不舒服
a389366 Smart Linux:fix the compile of base-files
...
1
2
3
4
5
6
7
那麼我們應該怎麼修改呢?

第一步,回退到要修改的前一個提交點
$ git rebase -i a389366
1
關於這個命令檢視:

git rebase -i  [startpoint]  [endpoint]
1
其中-i的意思是--interactive,即彈出互動式的介面讓使用者編輯完成合並操作,startpoint則指定了一個編輯區間,如果不指定[endpoint],則該區間的終點預設是當前分支HEAD所指向的commit(注:該區間指定的是一個前開後閉的區間)。

在彈出的vim編輯器中
  1 pick 6d5aca7 Smart:add bootimage target
  2 pick e14fcfa Smart Linux:load fw issue
  3 pick bd45a6f Smart Linux:optimize Audio driver and auto load
  4 pick b536e0c Smart Linux:enable adbd
  6 # Rebase a389366..b536e0c onto a389366 (4 command(s))
  5
  7 #
  8 # Commands:
  9 # p, pick = use commit
 10 # r, reword = use commit, but edit the commit message
 11 # e, edit = use commit, but stop for amending
 12 # s, squash = use commit, but meld into previous commit
 13 # f, fixup = like "squash", but discard this commit's log message
 14 # x, exec = run command (the rest of the line) using shell
 15 # d, drop = remove commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
將第一行的關鍵詞pick改成edit,看第11行提示:

e, edit = use commit, but stop for amending
1
改之後就是這樣:

  1 edit 6d5aca7 Smart:add bootimage target
  2 pick e14fcfa Smart Linux:load fw issue
  3 pick bd45a6f Smart Linux:optimize Audio driver and auto load
  4 pick b536e0c Smart Linux:enable adbd
1
2
3
4
然後,按:wq退出,會有這個提示:
You can amend the commit now, with

        git commit --amend

Once you are satisfied with your changes, run

        git rebase --continue

1
2
3
4
5
6
7
8
我們先按照提示修改註釋內容:
$ git commit --amend
Smart Linux:images:add bootimage target
1
2
在Smart 後面加了Linux,然後儲存退出。

然後再基線讓rebase繼續:
$ git rebase --continue
Successfully rebased and updated refs/heads/master.
1
2
然後看下git log,確認下是否改過來了
$ git log
b536e0c Smart Linux:enable adbd
bd45a6f Smart Linux:optimize Audio driver and auto load
e14fcfa Smart Linux:load fw issue
6d5aca7 Smart Linux:add bootimage target #這一次提交少了一個Linux,強迫症看著不舒服
a389366 Smart Linux:fix the compile of base-files
...
1
2
3
4
5
6
7
然後再推上去
git push --force origin master