首页 > 解决方案 > 如何压缩 git 历史中的一系列提交?

问题描述

我想将多个提交压缩在一起,但它们都不是当前的负责人。这是它的样子:

commit 7e3641f857b4fb15362c43354de5f14846a461b1 (HEAD -> superset-custom-exporter, origin/superset-custom-exporter)
Author: Aviral Srivastava
Date:   Wed Nov 4 11:41:32 2020 -0500

    adds env vars pertaining to postgresdb deployment with odh

commit bae9321ea4f78973adcc50c92a10eaebd703c7eb
Author: 
Date:   Wed Oct 21 08:55:37 2020 -0300

    Fix the security role for new logged in users

commit 2974314ca485c526ed2272f6c8bad443653765ab
Author: 
Date:   Thu Oct 15 13:39:08 2020 -0400

    Revert "wip"
    
    This reverts commit 0a93c50120b49a6ad850ee0cf8b1ab0523d50f97.

commit second_commit
Author: 
Date:   Thu Oct 15 11:50:24 2020 -0400

    wip

commit some_commit
Author: 
Date:   Thu Oct 15 10:30:47 2020 -0400

    Upgrade to superset version 0.37.2

commit some_commit
Author: 
Date:   Thu Oct 22 12:40:49 2020 -0400

    wip

commit some_commit
Author: 
Date:   Thu Oct 22 12:19:47 2020 -0400

    adds slices monitoring

commit first_commit
Author: 
Date:   Thu Oct 15 16:07:03 2020 -0400


我想将提交从哈希second_commit压缩first_commit到一个单独的提交。我了解如何从当前具有过去范围的当前执行此操作,但是当两个提交都过去时,我不知道如何执行此操作。

标签: git

解决方案


实际上,要压缩您的项目,您不仅应该移动头部,还应该将 master 移动到相同的位置。

要做到这一点 1.你应该在软中重置 >>>>>> git reset --soft [第二次提交的哈希值] 2.将你修改的提交作为下一次提交 >>git commit -am "The last commit"

现在你已经被压扁了。实际上,使用“git log --oneline”而不是“git log”命令。它会缩短您的文本。


推荐阅读