eFo*_*Fox 5 git command-line git-rebase windows-10
在将一个分支重新建立到另一个分支上后,我遇到了一个有趣的问题;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
Run Code Online (Sandbox Code Playgroud)
运行git log并gitk会显示应有的历史记录,这是我当前的提交和它最初基于的功能分支的较旧提交,如预期的那样。然而,如果我随后运行,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
Run Code Online (Sandbox Code Playgroud)
但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
Run Code Online (Sandbox Code Playgroud)
我尝试在本地删除分支并从远程存储库中提取一个新分支:
git checkout DevelopmentBranch
git branch -D NewFeatureBranch
git checkout -b NewFeatureBranch origin/NewFeatureBranch
Run Code Online (Sandbox Code Playgroud)
我尝试通过增加 中的提交来获取更多历史记录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
Run Code Online (Sandbox Code Playgroud)
但问题仍然存在。
我想我可以尝试进行软重置并修改我想要压缩的提交:
git reset --soft HEAD~1
Run Code Online (Sandbox Code Playgroud)
但这并不能解决我当前的git rebase -i HEAD~n历史混乱的问题。
但是,如果我随后运行 git rebase -i HEAD~4 我会得到旧分支的历史记录以及 11 次提交,而不是我要求的 4 次:
您的提交之一是合并。每当您尝试squash[交互式变基]时,您都会获得所有提交。如果中间有合并,您将获得该合并的所有提交。
| 归档时间: |
|
| 查看次数: |
7247 次 |
| 最近记录: |