git 远程提交合并
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-02 09:47:56
0
2
590

例如远程master分支上有100次提交记录

现在想把1-10次提交合并成一次提交,【就好像我只提交过一次一样】其他11-100次提交保持不变。如何实现?

看了git rebase -i ,好像只能合并本地分支,合并以后怎么影响远程分支呢?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
阿神

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

巴扎黑

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):

  1. Create a new branch based on the current branch: git checkout -b newBranch

  2. Roll back to before the first commit on a new branch: git reset --hard <commit1Hash>

  3. Cherry pick the first ten commits and put them in the buffer: git cherry-pick -n <commit1Hash>..<commit10Hash>

  4. Submit these ten commits. git commit -m "<xxxx>"

  5. 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!