【问题标题】:How can I use rebase -i so that one commit contains changes of another one?如何使用 rebase -i 以便一个提交包含另一个提交的更改?
【发布时间】:2018-06-26 12:22:47
【问题描述】:

考虑这种情况。我有 5 次提交 A-B-C-D-E。我想使用 rebase -i 以便提交 B 将具有提交 D 的所有更改。我该怎么做?

【问题讨论】:

标签: git commit rebase


【解决方案1】:

你可以简单地做git rebase -i HEAD~4然后你会看到

pick ae2c481 B
pick 2b1007f C
pick bcda8c5 D
pick 8591cea E

# Rebase 69f1cd1..8591cea onto 69f1cd1 (4 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

然后做

pick ae2c481 B
squash bcda8c5 D
pick 2b1007f C
pick 8591cea E

【讨论】:

  • 谢谢,顺便说一句,我还想问一件事。考虑一下我提交 A-B-C-D-E 的情况。提交 D 添加到我的代码中,例如一个类。但我希望从提交 B 中包含该更改并删除提交 D 中的此更改。我该怎么做?
  • 你想要提交 B 中提交 D 的一部分吗?
【解决方案2】:
git rebase -i A

编辑器弹出内容:

pick B
pick C
pick D
pick E

编辑内容:

pick B
squash D
pick C
pick E

保存并退出。

【讨论】:

    猜你喜欢
    • 2013-01-13
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 2019-10-29
    • 2021-09-22
    • 2014-06-13
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多