Squashing all of my commits (including merges) into one commit without altering history

蹲街弑〆低调 提交于 2019-12-24 15:01:33

问题


Say I have 100 commits in my branch that I've been working on for 3 weeks. Occasionally (every day, really) I pull from origin/master and merge it into my branch.

How could I (easily) go about squashing all of my commits into one commit without messing up history? If I squash all of my commits into one somehow, would I destroy the merged origin/master pulls when my pull request gets moved into origin/master?


回答1:


"Squashing" and "preserving history" are approximately direct opposites in terminology.

If you mean that you want to make a single commit that includes only your changes and not the ones from upstream master, you would probably want to rebase onto origin/master and then squash from there. You could do all of this from a single invocation of interactive rebase:

git fetch origin
git rebase -i origin/master

and then change all of the lines after the first from pick to squash.



来源:https://stackoverflow.com/questions/9588935/squashing-all-of-my-commits-including-merges-into-one-commit-without-altering

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!