【问题标题】:How to squash 7 pushed commits into one in to 1 in git?如何在 git 中将 7 个推送的提交压缩为一比一?
【发布时间】:2018-10-22 11:13:21
【问题描述】:

我已经尝试了多种方法来压缩我的远程 repo 提交,但没有做对。我想把它们全部压扁,做成一个。以下是提交列表。以下是我对上游的拉取请求的摘要(其中列出了 7 个提交)。我只想列出一个而不是 7 个。

【问题讨论】:

标签: git git-rebase git-squash


【解决方案1】:
git reset --soft HEAD~7
git add --all
git commit
git push --force

首先,将 git index 重置为要压缩的提交之前。使用 --soft 以便 git 仅重置索引并且不会触及您的工作目录。然后像往常一样创建一个提交。

【讨论】:

    【解决方案2】:

    另一种方法是使用squash - 我的其他工作interactive rebase

    要执行 git squash,请按照以下步骤操作:

    # X is the number of commits you wish to squash, in your case 7
    # In this interactive rebase there can be more that 7 commits if
    # there was a merge in one of them
    git rebase -i HEAD~X
    

    压缩提交后 - 选择 s 进行压缩 = 它将所有提交合并为一个提交。

    【讨论】:

    • 你的回答也是正确的。但我已经得到了正确的答案。并且没有选项可以勾选两个答案“正确”。 :)
    猜你喜欢
    • 2011-08-05
    • 2010-12-12
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 2017-10-16
    相关资源
    最近更新 更多