git 如何删掉一个远程的 commit

2018-10-10 12:36:40 +08:00
 shazh520

现在的状态是这样:

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

前辈们支支招,诚谢.

6318 次点击
所在节点    git
12 条回复
yianbin
2018-10-10 12:57:03 +08:00
git push -f -u origin master 试试?
samuel37
2018-10-10 13:14:52 +08:00
为什么不直接把 repo 删了呢?
把错误的 commit revert 再 push。
lnim
2018-10-10 13:17:13 +08:00
本地修改好 push -f
jowan
2018-10-10 13:18:34 +08:00
先退回:reset --soft 版本
再强行 push 远程库:git push -f
接下来 把同步版本后增加的 commit 提交就可以了

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

如果一定要删,就 reset 之后 push --force,不过做好被同事打的心理准备……
icylogic
2018-10-10 14:02:01 +08:00
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
2018-10-10 14:04:57 +08:00
我一般是从出错前一个 commit 拉个 branch
CoCoMcRee
2018-10-10 14:06:44 +08:00
我一般是从出错的分支先改个名字(本地和远端都改), 再前一个 commit 拉个 branch , 然后把正确的再合过来, 然后把推到远端,再把名字改回来, 把之前出错的分支删掉就好了, 这样远端就相当于没有了这个出错的 commit
Raymon111111
2018-10-10 14:17:30 +08:00
reset 然后 push force

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/496266

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX