删除 git 中的多个旧提交
假设我有一个包含一堆提交的分支,有没有一种方法可以删除其中几乎所有的提交,除了最后 2 或 3 个提交?
例如,我的分支上有这个:
+ Commit1
+ Commit2
+ Commit3
+ Commit4
+ Commit5
+ Commit6
+ Commit7
+ Commit8
+ Commit9
+ Commit10
+ Commit11
+ Commit12
+ Commit13
+ Commit14
+ Commit15
+ Commit16
+ Commit17
+ Commit18
+ Commit19
+ Commit20
+ Commit21
+ Commit22
+ Commit23
+ Commit24
+ Commit25
+ Commit26
+ Commit27
+ Commit28
我只想保留 Commit26、Commit 27
和 Commit28
(可以这么说,是最近的)
有没有办法可以这样做吗?
Let's say I have a branch with a bunch of commits in it, it's there a way where I can delete almost all of the commits in there, except for the last 2 or 3 ones?
For example, I have this on my branch:
+ Commit1
+ Commit2
+ Commit3
+ Commit4
+ Commit5
+ Commit6
+ Commit7
+ Commit8
+ Commit9
+ Commit10
+ Commit11
+ Commit12
+ Commit13
+ Commit14
+ Commit15
+ Commit16
+ Commit17
+ Commit18
+ Commit19
+ Commit20
+ Commit21
+ Commit22
+ Commit23
+ Commit24
+ Commit25
+ Commit26
+ Commit27
+ Commit28
I only want to keep Commit26, Commit 27
and Commit28
(the most recent ones, so to speak)
Is there a way I can do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 git rebase -i
我建议在你的情况下
然后你删除你不想保留的提交
你会得到类似
删除行的东西:
I recommend to use
git rebase -i
On your case
Then you delete the commit you don't want to keep
You will get something like
just delete lines to get: