gpt4 book ai didi

git - 还原项目 20 多个提交,然后有选择地仅重新应用其中的一些

转载 作者:太空狗 更新时间:2023-10-29 14:03:10 25 4
gpt4 key购买 nike

我有一个 git 项目,其中进行了多次提交,我想还原其中的大部分。但是,在这段时间内,我想保留一些错误修复和其他提交,因此我想执行以下操作:

  1. 将存储库恢复到我要恢复的第一次提交之前的提交
  2. 检查提交并仅重新应用其中的一些,其中一些仅部分应用

是否有一些 git 命令序列可以让我实现这一目标?我可以想出如何恢复到某个提交,但我不知道是否有可能进行选择性重新提交。

最佳答案

您不必还原。您可以使用 git rebase in interactive mode编辑您的历史记录。例如,在我当前的主题分支上,如果我运行 git rebase -i master我在 VIM 中得到这个 View :

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

从这个 View 我可以删除我不想提交的行,如果我真的不想删除金丝雀测试我可以删除或注释掉该行或使用 drop 命令.我可以在提交时停止 rebase 并更改将使用 edit 提交的内容(您可以通过删除更改在此处提交 部分 )等等列出的其他命令:

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

对于您的情况和针对您自己而不是其他分支的 rebase ,您可以回顾 git log找到要还原到的提交的提交哈希。这通常是您开始的工作之前的一次提交:git rebase -i <where to "revert"> .

关于git - 还原项目 20 多个提交,然后有选择地仅重新应用其中的一些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51214230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com