gpt4 book ai didi

git - git rebase -i重新设置并强制推送后显示错误的提交历史记录

转载 作者:行者123 更新时间:2023-12-02 04:31:35 27 4
gpt4 key购买 nike

在将一个分支重新部署到另一个分支后,我遇到了一个有趣的问题; git rebase -i HEAD~n不仅显示错误的提交历史记录(旧分支),而且显示错误的提交量。

我想做的事

我希望能够在正确的提交历史记录上执行git rebase -i HEAD~n,以便压缩我基于其分支的旧分支中的剩余提交。

我造成问题的原因

# On another Feature branch
git branch -b NewFeautureBranch
# Develop my commit
git add editedfile.extension
git commit -m "Commit message"
# I squashed and merged the feature branch into the development branch, as well as some other feature branches
git fetch --all
git checkout DevelopmentBranch
git pull
git checkout NewFeatureBranch
git rebase DevelopmentBranch
git push -f

运行 git loggitk将按原样显示历史记录,这是我当前的提交以及它最初基于的功能分支中的较早提交,这符合预期。但是,如果我随后运行 git rebase -i HEAD~4,则会得到旧分支的历史记录以及11次提交,而不是我要求的4次提交:
# Git rebase -i HEAD~4 opens up in VIM like this:
pick f79316dc Commit on old Branch base
pick ba742f2f Commit on old Branch base
pick 7577ea7a Commit on old Branch base
pick 91c4088c Commit on old Branch base
pick 98feed6d Commit on old Branch base
pick e8a73d78 Commit on old Branch base
pick 198f79e7 Commit on old Branch base
pick 10bb699c Commit on old Branch base
pick 1d15a926 Commit on old Branch base
pick 0cf569bb Previous commit I want to squash with
pick 470de8d9 Current FeatureBranch commit

但是 git log显示如下:
# As it should be when seeing git log and gitk
commit 470de8d92bb490dd14c31d5741b7edec82ca7597 (HEAD -> FeatureBranch, origin/FeatureBranch)
Author: evFox <evFox@fake-email.com>
Date: Wed Jan 3 16:08:24 2018 +0100
Feature commit message

commit 0cf569bba43b5747831a28d6cb42209dab1c2ffa
Author: evFox <evFox@fake-email.com>
Date: Wed Jan 3 12:09:48 2018 +0100
Feature from old branch still relevant to this; what I want to merge with the later commit.

commit 982c30d9c3b46539340fe48c241192e377d3e136 (origin/Development, Development)
Merge: ab6e7c9d 1d15a926
Author: evFox <evFox@fake-email.com>
Date: Tue Jan 9 10:51:06 2018 +0000
Merged PR XX: Merge OldFeatureBranch to Development

我尝试过的

我试图在本地删除分支,并从远程存储库中提取一个新分支:
git checkout DevelopmentBranch
git branch -D NewFeatureBranch
git checkout -b NewFeatureBranch origin/NewFeatureBranch

我试图通过增加 git rebase -i中的提交来获取更多历史记录,并且我可以清楚地看到这些提交是旧的,与更新和合并之前一样,属于OldFeatureBranch:
# Git rebase -i HEAD~20 opens up in VIM like this:
pick bt67f432 Commit on old version DevelopmentBranch
pick 5g67f33s Commit on old version DevelopmentBranch
pick rt53d563 Commit on old version DevelopmentBranch
pick ew5r45fg Commit on old version DevelopmentBranch
pick 9gy3f74f Commit on old version DevelopmentBranch
pick 58u5hh63 Commit on old version DevelopmentBranch
pick 34fdg5d5 Commit on old version DevelopmentBranch
pick n678hcn7 Commit on old version DevelopmentBranch
pick mh7y88dr PR merge of DevelopmentBranch where old Branch base were branched out originally, but not where DevelopmentBranch was when old Branch Base was squashed and merged.
pick f79316dc Commit on old Branch base
pick ba742f2f Commit on old Branch base
pick 7577ea7a Commit on old Branch base
pick 91c4088c Commit on old Branch base
pick 98feed6d Commit on old Branch base
pick e8a73d78 Commit on old Branch base
pick 198f79e7 Commit on old Branch base
pick 10bb699c Commit on old Branch base
pick 1d15a926 Commit on old Branch base
pick 0cf569bb Previous commit I want to squash with
pick 470de8d9 Current FeatureBranch commit

但是问题仍然存在。

可能的解决方法

我想我可以尝试进行软重置并修改要压缩的提交:
git reset --soft HEAD~1

但是,这并不能解决我当前困扰 git rebase -i HEAD~n历史记录的问题。

最佳答案

但是,如果我随后运行git rebase -i HEAD〜4,则会得到旧分支的历史记录以及11次提交,而不是我要求的4次:

您的提交之一是合并。每当您尝试squash [interactive rebase]时,您都将获得所有提交。如果中间有合并,您将获得此合并的所有提交。

关于git - git rebase -i重新设置并强制推送后显示错误的提交历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48183264/

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