gpt4 book ai didi

github - 想要压缩 github 中的多个提交

转载 作者:行者123 更新时间:2023-12-02 08:53:42 25 4
gpt4 key购买 nike

我想用提交消息“第一”和“第二”压缩两个最新提交。首先我拉 master 然后我使用命令

git rebase -i HEAD~2 master

它向我显示了编辑器中的两次提交,如下所示:

pick first
pick second

然后我将此编辑器更改为:

pick first
squash second

保存更改后,我收到此消息:

Successfully rebased and updated refs/heads/master.

它确实改变了远程主控中的任何内容。为了应用这些更改,我使用 git push 命令并收到以下错误:

To https://github.com/aneelatest/GITtest.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/test/GITtest.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

然后我再次运行 git pull 命令,它合并 origin master 并使用此提交消息进行另一次提交:

Merge branch 'master' of https://github.com/aneelatest/GITtest

此后,当我运行 git Push 时,它将两个提交压缩为一个,并带有消息“first”。问题是在远程主控中,我现在有四个提交:

first
second
Merge branch 'master' of https://github.com/test/GITtest
first

我只想要一个提交,即带有提交消息“第一个”的压缩提交。有什么想法我做错了吗?

最佳答案

git rebase 重写历史记录,因为提交已被修改。当上述提交尚未推送到远程存储库时,这不是问题,但这里远程存储库之前已使用您重写的提交进行了推送,因此它拒绝了推送。

当你从 github 拉取时,它合并了两个历史记录,并应用了你的南瓜提交,因此造成了困惑。

结论:当你想重写已经推送的提交时,你有两个选择:

  • 不要这样做
  • 执行git push --force,这也会在远程重写历史记录,并告诉人们您已经重写了历史记录,这样他们在下一次拉取时就会看到奇怪的事情。<

关于github - 想要压缩 github 中的多个提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17670717/

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