Remove Commit from Repository History
Possible Duplicate:
How to delete a 'git commit'
Knowing that this will change history, I want to remove some accidentally commits from the history of a repository. I would like all other commits to retain their states of the repository. So the changes of commits I want to delete would be covered each by the commit after them.
How can I do that in Git and how can I apply that also or only to the repository on Github?
If I understand correctly, "squashing" is what you want.
-A-B-C-D-E-F-G-H
Given the history above, you should pick the commit before the first commit you want to squash. Let's say you want to squash F and E into D and H into G, so the commit before the first one is C.
git rebase -i C
You will be presented an editor with a text file containing something like the following:
pick D
pick E
pick F
pick G
pick H
Modify this into:
pick D
squash E
squash F
pick G
squash H
You will be asked to review the commit messages of the new commits,
The resulting history will look like:
-A-B-C-D'-G'
Please note You're always squashing newer commits into older ones, not vice versa. Therefore pick G
and squash H
. Think of it as amending a commit after your history moved on.
PS: To get this into your GitHub repository, you'll have to to a forced push git push -f origin
(given that origin
is your GitHub remote).
PPS: For further information see the man page of git-rebase.
链接地址: http://www.djcxy.com/p/9000.html下一篇: 从存储库历史中删除提交