【问题标题】:Git script to rebase and squash temporary commits用于变基和压缩临时提交的 Git 脚本
【发布时间】:2016-10-22 04:02:08
【问题描述】:

在我压缩 Git 提交的几次中,我需要一些手动工作来选择我想要压缩的以前的提交。

有什么方法可以自动实现这一点 - 我的目标是压缩所有之前尚未推送到特定远程分支的提交。

详细地说,假设我有 1 个名为“dev”的本地分支和 2 个远程,公共和私有。我提交并将我想要的所有内容推送到私有远程,到一个名为“dev”的分支,我们称之为private/dev。但是在公共遥控器上,我想保持干净整洁,并保持一个名为“master”的标准分支,我们称之为public/master。所以就像我说的,对于所有尚未提交到公共远程 master 分支的提交,我想将它们压缩成一个大提交,然后推送到 public/master

我怎样才能做到这一点?看起来很复杂。

【问题讨论】:

标签: git github git-rebase git-squash


【解决方案1】:

您只需通过 public/master 创建一个临时分支(public 是您的公共远程的名称,master - 例如 - 作为目标分支)

而你使用merge --squash(见“In git, what is the difference between merge --squash and rebase?”)

 git checkout -b temp public/master
 git merge  --squash dev
 # since merge --squash does not produce a commit:
 git commit -m "squash dev"
 git push public temp:master
 git checkout dev
 git branch -d temp

关于冒号语法,请参阅“git push branch to a new repo with a different name”和examples section of git push
它允许将本地分支推送到具有不同名称的远程分支。

【讨论】:

  • 我希望这行得通。您能否详细说明每个步骤/命令中到底发生了什么?不确定我是否真的关注
  • 例如,能否给合并结果一个提交信息,当你查看最新版本的public/master时会用到?
  • 什么是“git push public tmp:master”——冒号语法是什么意思?
  • 我用有用的细节更新了我的问题,我会编辑你的答案以反映细节,如果我弄错了,请纠正我,谢谢。
  • @AlexanderMills 对! git merge --squash 不会产生提交。您需要一个额外的git commit -m。已编辑。
猜你喜欢
  • 2012-11-20
  • 1970-01-01
  • 2013-01-08
  • 2021-04-30
  • 2020-10-24
  • 1970-01-01
  • 2011-01-19
  • 1970-01-01
  • 2017-10-16
相关资源
最近更新 更多