How to remove all commits in Git except the latest one?
本问题已经有最佳答案,请猛点这里访问。
我想通过删除所有以前的提交并保留最新的提交来清除提交历史记录。我怎样才能在Git中做到这一点?我试过了
埃多克斯1〔0〕..但那似乎是以血液结束的,在那里我最终分离了我的头。
所以如果我承诺1到10。我现在只想把第10个带在身边。所有这些都是本地的。所以当我决定推的时候,我只推了10个。
程序在Git手册中描述:
Squashing Commits
It’s also possible to take a series of commits and squash them down into a single commit with the interactive rebasing tool. The script puts helpful instructions in the rebase message:
号
1 2 3 4 5 6 7 8 9 | # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. # |
If, instead of"pick" or"edit", you specify"squash", Git applies both that change and the change directly before it and makes you merge the commit messages together. So, if you want to make a single commit from these three commits, you make the script look like this:
号
1 2 3 | pick f7f3f6d changed my name a bit squash 310154e updated README formatting and added blame squash a5f4a0d added cat-file |
号
如果您不想将非常规提交压缩为一个,但实际上完全删除提交,那么请按照脚本要求执行以下操作:
1 | # If you remove a line here THAT COMMIT WILL BE LOST. |