gpt4 book ai didi

Git rebase 将当前分支留在远程,想要一个更干净的提交历史

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

我定期将本地 Git 存储库中的提交上传到 GitHub,但提交重载,在确定它们没有用且只会破坏历史后,我尝试使用 rebase -i 压缩一些一起提交。

它似乎有效,所以我想将更改的提交推送到 GitHub 并更改那里的历史记录。我得到的是我当前分支的提示落后了。建议的操作是从远程 repo 中提取更改,但我不希望从远程进行更改。我只想将我在本地的内容发送到 GitHub。

能否请您稍微解释一下情况并帮助实现我想要的?

最佳答案

编辑一些推送的分支是不行的,但是你可以这样做。

也许你的提交日志是这样的:

o 250a32c added new information <master> <origin/master>
|
o c4f5265 added new information
|
o 168d674 added new information
|
o ca708cd some other commit

您现在可以使用交互式 rebase 压缩一些提交。

git rebase -i ca708cd

编辑器打开,您可以将提交 250a32cc4f5265 之前的 pick 更改为 squash

在此之后,您的代码库如下所示:

o 3e86bc4 added new information <master>
| o 250a32c added new information <origin/master>
| |
| o c4f5265 added new information
| |
| o 168d674 added new information
|/
o ca708cd some other commit

现在你需要用--force把你的分支推送到github,因为你的master和master/origin不同步,不能快进。

git push --force origin master

关于Git rebase 将当前分支留在远程,想要一个更干净的提交历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18608817/

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