首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Git从commit N改为commit B

Git从commit N改为commit B
EN

Stack Overflow用户
提问于 2019-01-17 21:25:34
回答 1查看 44关注 0票数 1

是否可以从N个提交的列表中仅对特定的提交进行基址调整?

我总共有36次提交,我想从提交36次压缩到提交12次(从36次到12次,它们都是一个用户的提交,所有都是为了一个功能),如何做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-17 21:48:42

您可以使用interactive rebase来完成此操作。

代码语言:javascript
复制
git checkout <branch_with_commits>
git rebase -i HEAD~36

这将打开一个编辑器,其中所有的提交都被重新基址,以及为每个提交执行的操作,如下所示:

代码语言:javascript
复制
pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

对于您想要压缩的提交,将操作更改为squash (或您想要执行的其他操作)。保存并关闭编辑器以应用更改。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54236940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档