1. 程式人生 > >git revert 讓提交不再害怕

git revert 讓提交不再害怕

detail number ive 計算 comm -m res star The

git revert 讓提交不再害怕

使用了好多命令, 但對於 git revert 一直不敢怎麽使用, 為什麽呢?
因為 git merge 的存在.

每次 對於 git merge 的分支, 執行 git revert xxx 分支的時候總是報錯. 沒有細追.
今天同事恰好問道了這個問題. 於是追了一下.

主要就是對於 -m 命令. 查看了一下,其中對於

git revert -m 

解釋如下

 -m parent-number, --mainline parent-number
           Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the
           parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent.

           Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring
           in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want.

           See the revert-a-faulty-merge How-To[1] for more details.

正常使用的話, 那麽直接執行

git revert xxx(具體的某次提交的 SHA-1)

如果有某次merge的話

git revert -m 1 xxx (具體的某次提交)

這裏的 1 是什麽意思呢?

運行 git log 後, 當前的提交信息一般如下
commit

其中的 merge 第一個就是 1, 第二個就是 2, 依次計算;

一個比較好的參考地址如下:
how to revert-a-faulty-merge

git revert 讓提交不再害怕