gpt4 book ai didi

git - 如何 rebase (挤压)最后提交到 master 和更改提交消息

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

在 Git 中我有以下情况:

o "ok" b6ca869   [my_branch*]
|
o "ok" 479d27c
|
o "ok" c80fad5
|
o "ok" 8f7fe87
|
o "master commit message" [master][remotes/origin/master]

我想压缩这 4 个“ok”提交并进一步更改消息

o "my_branch commit message"    [my_branch*]
|
o "master commit message" [master][remotes/origin/master]

所以我做的是

git rebase --interactive master

GNU nano(我在 Ubuntu 上)编辑器打开

GNU nano 2.2.2             File: /home/.git/modules/src/android/frameworks/base/rebase-merge/git-rebase-todo                                

pick 8f7fe87 ok
pick c80fad5 ok
pick 479d27c ok
pick b6ca869 ok

# Rebase aeedb8f..b6ca869 onto aeedb8f
#
# 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
#
# 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

据我所知,我必须编辑此文件,但实际上我不知道该怎么做。

最佳答案

您需要将最后 3 次提交压缩到第一次提交(s 代表 squash):

pick 8f7fe87 ok
s c80fad5 ok
s 479d27c ok
s b6ca869 ok

保存然后退出,一个新的缓冲区应该会 pop 所有的提交信息。只需在最后使用/修改您想要的提交,保存并退出。

关于git - 如何 rebase (挤压)最后提交到 master 和更改提交消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22959584/

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