git resolve wrong commit branch

[master] ... 0 - (1) - (m1) - 2 - (3) - 4
              \
[develop]      5 - 6 - 7

Note: The ones with brackets are all wrong commits, m1 is the merge commit, and each number represents the commit and commit number that need to be placed in the develop branch

My approach (it seems to be ok so far, not sure if it is correct):

git checkout master
git pull
git diff 0 1 > patch1    (这两步的主要想法是物理备份一下,万一改乱了,还有个修改记录)
git diff 2 3 > patch2

git revert m1 -m 2    (这样直接会将1 和 m1产生修改的所有文件反转)
git revert 3

At this point, the branch status is:

[master] ... 0 - (1) - (m1) - 2 - (3) - 4 - rm1 - r3
              \
[develop]      5 - 6 - 7

Then apply the bug commit to develop

git checkout develop
git pull

git cherry-pick 1
git cherry pick 3
(进入merge按照提示解决、继续)

The branch status at this point is:

[master] ... 0 - (1) - (m1) - 2 - (3) - 4 - rm1 - r3
              \
[develop]      5 - 1 - 6 - 7 - 3    (这里看commit的时间,进行的排序)

The above is an approximate record

References:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324388225&siteId=291194637