记录有惊无险的git操作【整理git commit顺序】

Backgroud:

公司要求每个版本的git commit都要发CR,然而CR的机制是会将同一个branch的全都交上去。然而我修改的两个feature忘记切换branch了。

git log显示

pick 3894321 upload NAC folder setting  #A
pick 4d13523 auto sync to prod          #B
pick c29f76c auto sync to prod          #B
pick f8fe23c 1.split select realm and fee definition 2.fill all countries 3.add select label 4.filter 'NG' 5.delete id in option         #B
pick 7a0be73 1.sort fee definition by version 2.get realm select according response realm attributes                        #B
pick 9bc65cb pray for approvals         #B
pick a1d119b pray for last version      #B
pick 729769e upload NAC folder setting  #A
pick bec1592 little fix about var name  #B

然后就杯具了

请教我当时来的二面大哥,解决了问题

Solution:

1.先拆出分支

git checkout -b tmp

2.当前的log

git log
commit bec159267320a65624ac0ce29a068a34ad10fa96 (HEAD -> tmp, settingFolder)
Author: yujzhou <yujzhou@x.com>
Date:   Fri Jul 5 15:09:27 2019 +0800

    little fix about var name

commit 729769e0a0b3b992f13ae3cab07b423fe9f4edb3
Author: yujzhou <yujzhou@x.com>
Date:   Fri Jul 5 15:00:50 2019 +0800

    upload NAC folder setting

commit a1d119b90e4ba2904defca2bf7d41dd27a64a6df
Author: yujzhou <yujzhou@x.com>
Date:   Wed Jul 3 18:17:43 2019 +0800

    pray for last version

commit 9bc65cbd9aef7fb5a4de28229556ee0f3cc164e5
Author: yujzhou <yujzhou@x.com>
Date:   Wed Jul 3 16:20:04 2019 +0800

    pray for approvals

commit 7a0be738dc877fd2415d9cbecb92d01a1f0f5e33
Author: yujzhou <yujzhou@x.com>
Date:   Wed Jul 3 14:17:09 2019 +0800

    1.sort fee definition by version
    2.get realm select according response realm attributes

commit f8fe23c9ace599580b11c685fc5a2ffc425e1243
Author: yujzhou <yujzhou@x.com>
Date:   Wed Jul 3 11:25:57 2019 +0800

    1.split select realm and fee definition
    2.fill all countries
    3.add select label
    4.filter 'NG'
    5.delete id in option

commit c29f76c164d71776d4387b1d0b834f3aa33f6e1b
Author: yujzhou <yujzhou@x.com>
Date:   Mon Jul 1 19:37:17 2019 +0800

    auto sync to prod

commit 4d135238f72fe3f7738be0979b284b4b5804f1b1
Author: yujzhou <yujzhou@x.com>
Date:   Mon Jul 1 18:29:57 2019 +0800

    auto sync to prod
    
    cr https://code.amazon.com/reviews/CR-10216273

commit 3894321e2303ffb9a09ba7bf47d8be067f289e6e (origin/settingFolder)
Author: yujzhou <yujzhou@x.com>
Date:   Fri Jun 28 16:42:12 2019 +0800

    upload NAC folder setting
    
    cr https://code.amazon.com/reviews/CR-10118892

commit 4076a0bc86cbd57630f2f3e323c2d36ac448b266 (origin/mainline, origin/HEAD, mainline)

3.修改base

 git rebase -i 4076a0bc86cbd57630f2f3e323c2d36ac448b266

调整顺序

变为

pick 3894321 upload NAC folder setting
s 729769e upload NAC folder setting
pick 4d13523 auto sync to prod
s c29f76c auto sync to prod
s f8fe23c 1.split select realm and fee definition 2.fill all countries 3.add select label 4.filter 'NG' 5.delete id in option
s 7a0be73 1.sort fee definition by version 2.get realm select according response realm attributes
s 9bc65cb pray for approvals
s a1d119b pray for last version
s bec1592 little fix about var name

4.显示log变为

 git log
commit 4367d1f096d6aa2820918df2595afa980b16ca7e (HEAD -> tmp)
Author: yujzhou <yujzhou@x.com>
Date:   Mon Jul 1 18:29:57 2019 +0800

    support fee defintion auto fill
    
    cr https://code.amazon.com/reviews/CR-10216273

commit ff8b9ba14ee453983791f4e9d82f950589723056
Author: yujzhou <yujzhou@x.com>
Date:   Fri Jun 28 16:42:12 2019 +0800

    upload NAC folder setting
    
    cr https://code.amazon.com/reviews/CR-10118892

commit 4076a0bc86cbd57630f2f3e323c2d36ac448b266 (origin/mainline, origin/HEAD, mainline)

(可选:再执行这个操作,修改commit注释内容)

5.再拆一个分支

git checkout -b uploadFolder

6.

 git log
commit 7d18fd815577f04fbe9f62531fd44ca2e314be98 (HEAD -> tmp)
Author: yujzhou <yujzhou@x.com>
Date:   Fri Jun 28 16:42:12 2019 +0800

    upload NAC folder setting
    
    cr https://code.amazon.com/reviews/CR-10118892

commit 7323697277e565634214e083d517838f3a9502f2
Author: yujzhou <yujzhou@x.com>
Date:   Mon Jul 1 18:29:57 2019 +0800

    support fee defintion auto fill
    
    cr https://code.amazon.com/reviews/CR-10216273

commit 4076a0bc86cbd57630f2f3e323c2d36ac448b266 (origin/mainline, origin/HEAD, mainline)

7.既然要提交次早的,就将最新的reset删除就好啦

git reset --hard 7323697277e565634214e083d517838f3a9502f2

提CR

8.切回分支

git checkout tmp
 git log
commit 7d18fd815577f04fbe9f62531fd44ca2e314be98 (HEAD -> tmp)
Author: yujzhou <yujzhou@x.com>
Date:   Fri Jun 28 16:42:12 2019 +0800

    upload NAC folder setting
    
    cr https://code.amazon.com/reviews/CR-10118892

commit 7323697277e565634214e083d517838f3a9502f2 (uploadFolder)
Author: yujzhou <yujzhou@x.com>
Date:   Mon Jul 1 18:29:57 2019 +0800

    support fee defintion auto fill
    
    cr https://code.amazon.com/reviews/CR-10216273

commit 4076a0bc86cbd57630f2f3e323c2d36ac448b266 (origin/mainline, origin/HEAD, mainline)

9.既然这个分支是删除次新的 那么将对应的pick那行删除即可

git rebase -i 4076a0bc86cbd57630f2f3e323c2d36ac448b266

提CR 完事~~

全部评论

相关推荐

牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
喜欢走神的孤勇者练习时长两年半:哈哈,还好是被挂,要是被违约,有你好受的
点赞 评论 收藏
分享
11-05 18:30
门头沟学院 Java
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务