git remote commit merge
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-02 09:47:56
0
2
651

For example, there are 100 commit records on the remote master branch

Now I want to merge 1-10 commits into one commit, [as if I only submitted once] and keep the other 11-100 commits unchanged. How to achieve?

After looking at git rebase -i, it seems that only local branches can be merged. How will the remote branches be affected after merging?

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

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