我试图将分支提交压缩到它最终 merge 到主节点中时(如果经过 pull 请求之后)提交历史看起来很干净。因此在提出 pull 请求之前我做了一个
git rebase -i
并重写历史记录。
但是,在其分支中开发要素时,我必须将母版的内容 merge 到该分支上,因为由于 merge 了其他要素分支,母版通常会向前移动。
我看到那些我 merge 了master到Feature分支的对象,我无法压扁他使用交互式rebase提交的任何内容。在 pull 请求期间,这会导致异常的差异,即更改是来自主服务器的 merge 的一部分。
在这种情况下,压缩提交的最佳方法是什么?
最佳答案
您可以使用soft reset
压缩分支(例如feature
)的提交。假设您在feature
分支中有5次提交。现在您需要5次提交= 1次新提交。
$ git checkout feature
$ git log # see how many commits do you need to squash
$ git reset --soft HEAD~4 # note: if you have N commits then HEAD~{N-1}
Or, git reset --soft <first-commit> # reset to first commit of your branch
$ git add . # add the files
$ git commit --amend -am 'Squash all commits' # squash all the commits
$ git push -f origin feature # force(-f) push to remote since git history is changed
现在,Pull master分支更改。
$ git pull origin master
现在使用GitHub GUI(浏览器)创建一个Pull请求。
关于git - 从母版 merge 后, Squash 功能分支提交,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42513931/