如何在GitHub上删除提交历史记录中的提交?

时间:2014-05-19 16:18:11

标签: git github

我想从GitHub上的提交历史中删除一些提交。

但是,我不想实际删除与特定提交相关联的代码。我只想删除提交在提交历史记录中。这可能吗?如果是这样,怎么样?

谢谢!

1 个答案:

答案 0 :(得分:1)

你需要的是压制提交。

您想查看this article以获取更多信息

想象一下,您有3个要转换为1的提交,因为所有这些提交都应该是一次提交,因此您希望获得新功能提交和许可提交。它们以相反的顺序出现(第一次提交是最早的)

首先重新定位当前分支

$ git rebase -i HEAD~4

pick 9420b31 New feature
pick 8414d83 Adding license to code
pick 7bfb349 More info into the license
pick c79e70f Fixing license

# Rebase 93275f0..9420b31 onto 93275f0
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#

然后从" pick"更改许可提交。到#34; fixup" (如果你想丢弃提交信息)或"壁球" (如果你需要保留它)。

在这个例子中,那将成为

$ git rebase -i HEAD~4

pick 9420b31 New feature
pick 8414d83 Adding license to code
fixup 7bfb349 More info into the license
fixup c79e70f Fixing license

# Rebase 93275f0..9420b31 onto 93275f0
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#

之后,您只有两次提交:一次添加功能,另一次添加许可证(但是,代表许可证提交的哈希值会发生变化)。

只需注意一句:如果您已将历史记录推送到远程服务器,则可能需要" push --force"他们。如果某人克隆了该回购,他们在更新时可能会遇到问题(冲突)。

相关问题