修改github历史

时间:2016-02-08 11:26:26

标签: git git-commit

我提前为提出这个问题道歉,因为它已被问过一百万次了。

我需要修改项目的git历史记录, 提交历史目前如下所示:

[E] <- [D] <- [C] <- [B] <- [A]

其中: 答:添加了一些代码, B:添加了一些代码&amp;添加了一些数据, C:重组项目, D:删除了所有数据, E:添加了一些代码

问题在于,在提交C时,我们的项目组被通知数据必须存储在本地而不是公开存储在git上。我对git不太熟悉,所以我做的第一件事就是删除数据。但这并没有太大作用,因为数据仍然可以在历史中访问。如何解决问题,以便历史记录如下:

[E] <- [C] <- [B] <- [A]

其中: 答:添加了一些代码, B:添加了一些代码, C:重组项目(没有任何数据引用) E:添加了一些代码

2 个答案:

答案 0 :(得分:4)

以下是从历史记录中删除特定提交的方法

git rebase --onto commit-id commit-id HEAD

您可以使用以下命令删除提交&#34; D&#34;来自历史

git rebase --onto D E HEAD

答案 1 :(得分:1)

您可以使用以下命令执行此操作:

# Rebase from C commit in interactive mode...
git rebase -i C

# Then remove the D commit line in the editor, save and quit.
# You can edit commit messages by using "edit" option for
# concerned commits.
# Resolve conflicts if needed and finish rebasing.

OR(没有提交消息编辑):

# Rebase from C: Pick E history but exclude D history
git rebase --onto C D E

然后你必须推动修改(带来所有可能导致的麻烦......)。

# --force-with-lease means:
# "If anybody already pushed after the last known origin/<branch> sha1,
# The push force command will be aborted (avoids to loose newers pushes
# from your friends...).
git push --force-with-lease origin <branch>
相关问题