git 如何删掉一个远程的 commit - V2EX
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
shazh520
V2EX    git

git 如何删掉一个远程的 commit

  •  
  •   shazh520 Oct 10, 2018 7046 views
    This topic created in 2795 days ago, the information mentioned may be changed or developed.

    现在的状态是这样:

    git log

    至于为什么会出现这种情况呢,是我在一次 checkout revision 之后,重新写了代码并提交了。现在我想把那个多余的 commit 删除掉,master 和 origin 都还指向它。现在我每次提交都会显示下面这个弹窗 弹窗

    前辈们支支招,诚谢.

    12 replies    2018-10-1014:17:30 +08:00
    yianbin
        1
    yianbin  
       Oct 10, 2018
    git push -f -u origin master 试试?
    samuel37
        2
    samuel37  
       Oct 10, 2018
    为什么不直接把 repo 删了呢?
    把错误的 commit revert 再 push。
    lnim
        3
    lnim  
       Oct 10, 2018 via iPhone
    本地修改好 push -f
    jowan
        4
    jowan  
       Oct 10, 2018
    先退回:reset --soft 版本
    再强行 push 远程库:git push -f
    接下来 把同步版本后增加的 commit 提交就可以了

    我一般都是这样做的
    Deville
        5
    Deville  
       Oct 10, 2018   1
    同 1L ,另外。。 有个建议。。个人习惯。。 觉得 commit 还是正式化些比较好。。少些口语表述。。
    que01
        6
    que01  
       Oct 10, 2018
    修改 .git/refs/heads/branch_name 里面的版本号(这个版本号要注意长度) 这样指向的就是目标版本号 并记住后面几次有效的版本号 使用 git cherry-pick aaa1111 bbb222 ccc333 这样重做有效提交这块
    Ooooooooozil
        7
    Ooooooooozil  
       Oct 10, 2018   1
    commit message 推荐 http://gitmoji.carloscuesta.me
    icylogic
        8
    icylogic  
       Oct 10, 2018 via iPhone   1
    可以不删就尽量别删,比起删除一个 commit,更好的做法是用一个新的 commit 做 revert,并且写好为什么要这么做。

    如果一定要删,就 reset 之后 push --force,不过做好被同事打的心理准备……
    icylogic
        9
    icylogic  
       Oct 10, 2018 via iPhone
    revert 具体怎么做可以参考 https://www.atlassian.com/git/tutorials/undoing-changes/git-revert

    The git revert command can be considered an 'undo' type command, however, it is not a traditional undo operation. Instead of removing the commit from the project history, it figures out how to invert the changes introduced by the commit and appends a new commit with the resulting inverse content. This prevents Git from losing history, which is important for the integrity of your revision history and for reliable collaboration.
    CoCoMcRee
        10
    CoCoMcRee  
       Oct 10, 2018
    我一般是从出错前一个 commit 拉个 branch
    CoCoMcRee
        11
    CoCoMcRee  
       Oct 10, 2018
    我一般是从出错的分支先改个名字(本地和远端都改), 再前一个 commit 拉个 branch , 然后把正确的再合过来, 然后把推到远端,再把名字改回来, 把之前出错的分支删掉就好了, 这样远端就相当于没有了这个出错的 commit
    Raymon111111
        12
    Raymon111111  
       Oct 10, 2018
    reset 然后 push force
    About     Help     Advertise     Blog     API     FAQ     Solana     937 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 55ms UTC 22:06 PVG 06:06 LAX 15:06 JFK 18:0
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86