例如远程master分支上有100次提交记录
现在想把1-10次提交合并成一次提交,【就好像我只提交过一次一样】其他11-100次提交保持不变。如何实现?
看了git rebase -i ,好像只能合并本地分支,合并以后怎么影响远程分支呢?
阿神2017-05-02 09:49:56
git rebase -i HEAD~99
Then change the picks in front of the 10 furthest commits to squash.
Then force commit git push -f
Try it, I don’t know if it works
巴扎黑2017-05-02 09:49:56
The method mentioned above is correct, but it should be git rebase -i HEAD~100
吧。HEAD~99
It can only read 2 to 100 submissions, but not the first one.
In addition, after finding the 10 furthest commits, you don’t actually have to change it to squash (or s). If you don’t plan to keep the commit information, just use fixup (or f). .
It must be git push -f
after modification, because your timeline and subsequent commit hash have changed, of course your code will not change
Since it may take a long time to scroll from the last one to the first one. . Provide another idea (hereinafter, <xxx> is used to represent variables, and there is no need to type < and >. But other symbols must be typed):
Create a new branch based on the current branch: git checkout -b newBranch
Roll back to before the first commit on a new branch: git reset --hard <commit1Hash>
Cherry pick the first ten commits and put them in the buffer: git cherry-pick -n <commit1Hash>..<commit10Hash>
Submit these ten commits. git commit -m "<xxxx>"
Cherry pick remaining commits, not placed in buffer (directly added to timeline): git cherry-pick -n <commit11Hash>..<commit100Hash>
In this way, you have done what you want on a new branch. Just merge it into the branch you want to modify