git 将我的所有提交压缩为一份以用于 GitHub 拉取请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14534397/
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
Squash all my commits into one for GitHub pull request
提问by omerjerk
I made a pull request on GitHub. Now the owner of the repository is saying to squash all the commits into one.
我在 GitHub 上提出了一个拉取请求。现在存储库的所有者说要将所有提交压缩为一个。
When I type git rebase -i
Notepad opens with the following content:
当我输入git rebase -i
记事本时,会打开以下内容:
noop
# Rebase 0b13622..0b13622 onto 0b13622
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
I searched on Google but I do not understand how to do this.
我在谷歌上搜索,但我不明白如何做到这一点。
采纳答案by fontno
Just a simple addition to help someone else looking for this solution. You can pass in the number of previous commits you would like to squash. for example,
只是一个简单的补充,以帮助其他人寻找此解决方案。您可以传入您想要压缩的先前提交的数量。例如,
git rebase -i HEAD~3
This will bring up the last 3 commits in the editor.
这将在编辑器中显示最后 3 次提交。
回答by omerjerk
ok I figured it out ...
First I had to write git rebase -i xxxxxxxxxxxxxxxx
where xxxxxxxxxx is the SHA of the commit upto which I've to squash. Then in Notepad I edited the first as pick and rest of all as squash. Then a new notepad window will come and there in the first line I typed the name of my new commit.
And then I had to do a force push :
好的,我想通了......首先我必须写出git rebase -i xxxxxxxxxxxxxxxx
其中 xxxxxxxxxx 是我要压缩的提交的 SHA。然后在记事本中,我将第一个编辑为pick,其余的编辑为壁球。然后会出现一个新的记事本窗口,我在第一行输入新提交的名称。然后我不得不做一个强制推送:
git push --force origin master
回答by Stevoisiak
As of April 1, 2016, the repository's manager can squash all the commits in a pull request into a single commit by selecting "Squash and merge" on a pull request.
截至 2016 年 4 月 1 日,存储库的经理可以通过在拉取请求上选择“压缩并合并”将拉取请求中的所有提交压缩为单个提交。
If you want to manually squash commits in a pull request, refer to fontno's answer.
如果您想在拉取请求中手动压缩提交,请参阅fontno 的回答。
回答by Cong Wang
Try git rebase -i
, and use 'squash' for all the commits you want to squash.
尝试git rebase -i
,并使用 'squash' 来处理您想要压缩的所有提交。
Edit:
编辑:
git rebase -i
will show you an interactive editor with the list of commits you are rebasing. The default command before each commit is "pick", so you just need to s/pick/squash/ for all the commits you want to squash, and then all of them will be squash into their last previous commit.
git rebase -i
将向您显示一个交互式编辑器,其中包含您正在重新定位的提交列表。每次提交之前的默认命令是“pick”,所以你只需要 s/pick/squash/ 对所有你想压缩的提交,然后所有的提交都会被压缩到他们上一次提交中。
Make sure you are rebasing on a correct branch.
确保您基于正确的分支进行变基。