代码之家  ›  专栏  ›  技术社区  ›  Karlovsky120

恢复项目20+提交,然后选择性地重新应用其中的一些提交

  •  3
  • Karlovsky120  · 技术社区  · 8 年前

    我有一个Git项目,其中有几个提交,我想恢复其中的大部分。但是,在这段时间内,有几个bug修复和其他提交需要保留,因此我希望执行以下操作:

    1. 将存储库还原为我要还原的第一次提交之前的提交
    2. 执行提交并仅重新应用其中的一部分,其中的一部分仅部分

    是否有一些git命令序列可以让我实现这一点?我可以弄清楚如何恢复到特定的提交,但如果有选择地重新提交是可能的,我就一无所知。

    1 回复  |  直到 8 年前
        1
  •  3
  •   worc    8 年前

    git rebase in interactive mode git rebase -i master

    pick 23299aa6 improve unit test messages
    pick cf1c3c0c move sagas tests to where they'll get run
    pick f7ff7fa7 use docker-compose up to rebuild the ui image more quickly
    pick 544902ec split definitions file into helpers and given, when, then files
    pick 55e94e7b remove canary test
    pick 8a4b0862 move expectTitleToBe function to helper file
    
    # Rebase 72b74f26..8a4b0862 onto 72b74f26 (6 commands)
    #
    # Commands:
    # p, pick = use commit
    # r, reword = use commit, but edit the commit message
    # e, edit = use commit, but stop for amending
    # s, squash = use commit, but meld into previous commit
    # f, fixup = like "squash", but discard this commit's log message
    # x, exec = run command (the rest of the line) using shell
    # d, drop = remove commit
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out
    

    edit 23299aa6 improve unit test messages
    pick cf1c3c0c move sagas tests to where they'll get run
    pick f7ff7fa7 use docker-compose up to rebuild the ui image more quickly
    pick 544902ec split definitions file into helpers and given, when, then files
    drop 55e94e7b remove canary test
    pick 8a4b0862 move expectTitleToBe function to helper file
    
    # Rebase 72b74f26..8a4b0862 onto 72b74f26 (6 commands)
    #
    # Commands:
    # p, pick = use commit
    # r, reword = use commit, but edit the commit message
    # e, edit = use commit, but stop for amending
    # s, squash = use commit, but meld into previous commit
    # f, fixup = like "squash", but discard this commit's log message
    # x, exec = run command (the rest of the line) using shell
    # d, drop = remove commit
    #
    # These lines can be re-ordered; they are executed from top to bottom.
    #
    # If you remove a line here THAT COMMIT WILL BE LOST.
    #
    # However, if you remove everything, the rebase will be aborted.
    #
    # Note that empty commits are commented out
    

    git log git rebase -i <where to "revert">