三分钟教你学Git(二十七) - 修改多个commit
比如我們又一個歷史提交A->B->C->D, 當前HEAD在D commit上,我們想要修改B,C?commits,該怎么做呢?
我們知道用git commit --amend可以修改當前的提交D,但是之前的怎么辦呢?
首先我們要修改的起點開始于最近的三次提交,告訴git:
1 git rebase -i HEAD~3
然后git會告訴你現在的status:
pick a1?message of a1
pick a2?message of a2
pick a3?message of a3
?
# Rebase a10d0f8..b5f4d0d onto a10d0f8
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
?
2 上邊列出了你想要修改的命令, 比如我們只想修改最近三次的提交message:
reword a1?message of a1
reword a2?message of a2
pick a3?message of a3
3 然后退出并保存。
4 然后Git就會從commit B開始讓你進行修改。然后按照正常的流程修改完畢就行。
5 最后可以git log看一下歷史commit是否跟你的預期相符,好了,搞定了。
?
原文:http://blog.csdn.net/hongchangfirst/article/details/111056451
作者:hongchangfirst
hongchangfirst的主頁:http://blog.csdn.net/hongchangfirst
總結
以上是生活随笔為你收集整理的三分钟教你学Git(二十七) - 修改多个commit的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Face++人工智能开放平台、百度AI、
- 下一篇: Go之XORM操作MySQL