git 如何将 3 个提交压缩为 1 个?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44249276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Squash 3 commits into 1?
提问by Kaycee
I'm fairly new to git, so I've been trying to figure out how to squash 3 commits into 1 so my PR can get merged. I've read a lot of docs and guides and sort of found out how to squash commits but one of my commits aren't showing up. I tried attaching a photo of my commits and a photo of my terminal when I type in: "git rebase -i HEAD~5", but unfortunately I'm a new user so I can't? But anyway, I would greatly appreciate some help.
我对 git 相当陌生,所以我一直在试图弄清楚如何将 3 个提交压缩为 1 个,以便我的 PR 可以合并。我已经阅读了很多文档和指南,并且有点了解如何压缩提交,但我的一个提交没有出现。当我输入:“git rebase -i HEAD~5”时,我尝试附上我的提交照片和我的终端照片,但不幸的是我是一个新用户所以我不能?但无论如何,我将不胜感激一些帮助。
回答by danglingpointer
How to Squash 3 commits into 1?
如何将 3 个提交压缩为 1 个?
- do git log and confirm the commits you want to squash are commited, first.
- if you want squash top 3 commits from your head,
- 首先执行 git log 并确认您要压缩的提交已提交。
- 如果你想从你的头脑中压缩前 3 次提交,
Use this command,
使用这个命令,
git rebase -i HEAD~3
Here the tilde ~ symbol with 3 pick the top latest three commits and it will pop up in an interactive shell where you can select the top commit and squash other two commits into one by entering s, it means squash.
这里的波浪号 ~ 符号 3 选择最近的三个提交,它将弹出一个交互式 shell,您可以在其中选择顶部提交并通过输入 s 将其他两个提交压缩为一个,这意味着压缩。
If your commit is not appearing then do git log and see, if not then
如果您的提交没有出现,那么执行 git log 并查看,如果没有出现
git add files
git commit -m 'your commit'
回答by Kaycee
As of April 1, 2016 it is now possible for the repository administrator to perform Squashing of pull requests. However if you have been requested to do this yourself then:
从 2016 年 4 月 1 日起,存储库管理员现在可以执行拉取请求的压缩。但是,如果您被要求自己执行此操作,则:
回答by Raz
Squashing of commits means creation of a new commit instead of several. git reset
to the base commit of your branch and make a new one. Then just git push -f
to your branch.
压缩提交意味着创建一个新的提交而不是几个。git reset
到你的分支的基本提交并创建一个新的。然后就git push -f
到你的分行。
回答by Ivan86
Hey so GitHub has Squash And Merge option when merging a PR. So nothing you need to do on your end, just use option Squash and Merge when merging.
嘿,GitHub 在合并 PR 时有 Squash And Merge 选项。所以你不需要做任何事情,只需在合并时使用选项 Squash and Merge。
more info here https://help.github.com/articles/about-pull-request-merges/#squash-and-merge-your-pull-request-commits