简体   繁体   English

从提交ID到HEAD从分支到主节点自动对Git历史记录进行重设和压扁

[英]Automatically Rebase and Squash Git History From a Commit ID to HEAD from Branch to Master

Is it possible to use git rebase to remove all of the history from a specific commit to the HEAD revision? 是否可以使用git rebase从特定提交到HEAD修订中删除所有历史记录?

With git -i rebase , you have to count all of the commits in the git log and manually get squash of all of them except one commit before pushing the changes. 使用git -i rebase ,您必须计算git log中的所有提交,并手动获取除一次提交之前所有提交的压榨,然后再推送更改。

Is there a one-liner to do the following: 是否可以单线执行以下操作:

  1. git rebase -i HEAD~4 for 4 commits git rebase -i HEAD~4提交4次
  2. Within the text editor, squash everything and keep one pick (I think you have to pick at least one commit) 在文本编辑器中,压缩所有内容并保留一个选择(我认为您必须至少选择一个提交)
  3. git fetch origin to update the references git fetch origin更新参考
  4. git rebase origin/master to rebase the branch onto the master git rebase origin/master将分支重新建立到master
  5. git checkout master to switch to the master branch git checkout master切换到master分支
  6. git merge branch_name to merge the branch onto the master git merge branch_name将分支合并到主git merge branch_name

Is it possible to do this with less steps or other flags? 是否可以用更少的步骤或其他标志来做到这一点?

除了git rebase -i您还可以运行git rebase --soft <commit-id>HEAD移到<commit-id>而不更改索引或工作树,然后git commit创建一个新的提交,其中包含自<commit-id>

I believe what you're after is git commit --fixup . 我相信您所追求的是git commit --fixup Thoughtbot's writeup on automating this might interest you. Thoughtbot关于自动执行此操作的文章可能会让您感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM