【问题标题】:Convert pushed git commits into one将推送的 git 提交转换为一个
【发布时间】:2013-03-31 13:38:44
【问题描述】:

我正在为我所做的任何新项目使用样板。但是,我在样板文件中所做的提交会传递给新项目。我将如何简单地进行“初始提交”,其中包含一次提交中的所有内容并删除旧的提交历史记录?

【问题讨论】:

    标签: git project-management bitbucket git-reset


    【解决方案1】:

    您可以关注问题“git: how to squash the first two commits?”,并在您的新存储库中压缩 n-commits。
    script is here 可以压缩第一个提交,同时重放您希望保留在新仓库历史中的其余提交。

    git clone boilerplaterepo newrepo
    # apply the script for git reset --soft $1 everything
    

    该解决方案使用git reset --soft,是“Practical uses of git reset --soft?”之一的示例。


    如果您想要一个基于 rebase --interactive 的解决方案(不太实用,因为它涉及手动步骤),don't forget the --root option (git 1.7.12),以便重新调整到根提交。

     git rebase -i --root
     git push -f
    

    【讨论】:

      【解决方案2】:

      为此使用 rebase 命令

      git rebase -i HEAD~N

      N 是您想要合并为一个的提交数。 然后用力推一下..

      【讨论】:

      • 谢谢,这正是我所需要的。
      猜你喜欢
      • 2010-12-19
      • 2013-12-17
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      • 2015-01-16
      • 2017-12-22
      • 2014-05-06
      • 2020-01-20
      相关资源
      最近更新 更多