Git使用中,如果遇到某一次的提交不满意,可以使用如下方法修改
# git rebase -i HEAD~3 >>> HEAD~3表示列出最近三次的
之后会出现
1 pick 6e1bb94 modify
2 pick 1769e78 delete
3 pick 7ce9cad delete
4
5 # Rebase 491ed3f..7ce9cad onto 491ed3f
6 #
7 # Commands:
8 # p, pick = use commit
9 # r, reword = use commit, but edit the commit message
10 # e, edit = use commit, but stop for amending
11 # s, squash = use commit, but meld into previous commit
12 # f, fixup = like "squash", but discard this commit's log message
13 # x, exec = run command (the rest of the line) using shell
14 #
15 # These lines can be re-ordered; they are executed from top to bottom.
16 #
17 # If you remove a line here THAT COMMIT WILL BE LOST.
18 # However, if you remove everything, the rebase will be aborted.
19 #
20 # Note that empty commits are commented out
这样的可编辑文本,把后悔的提交由pick修改为edit,然后保存退出
这时会进入到no-branch状态,此时可以对这次提交进行修改,并使用
git commit --amend来覆盖
弄好后,使用git rebase --continue就可以回去了
怎么样,很方便吧?