git
› Pro Git
› Atlassian Git Tutorial
› Pro Git 简体中文翻译
› GitX
shazh520
V2EX  ›  git

git 如何删掉一个远程的 commit

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

    现在的状态是这样:

    git log

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

    前辈们支支招,诚谢.

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

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

    如果一定要删,就 reset 之后 push --force,不过做好被同事打的心理准备……
    icylogic
    icylogic
    Oct 10, 2018 via iPhone
    9
    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
    CoCoMcRee
    Oct 10, 2018
    10
    我一般是从出错前一个 commit 拉个 branch
    CoCoMcRee
    CoCoMcRee
    Oct 10, 2018
    11
    我一般是从出错的分支先改个名字(本地和远端都改), 再前一个 commit 拉个 branch , 然后把正确的再合过来, 然后把推到远端,再把名字改回来, 把之前出错的分支删掉就好了, 这样远端就相当于没有了这个出错的 commit
    Raymon111111
    Raymon111111
    Oct 10, 2018
    12
    reset 然后 push force
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2324 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 13:48 · PVG 21:48 · LAX 05:48 · JFK 08:48
    ♥ Do have faith in what you're doing.