如何压扁git后提交git? [英] How to squash commits in git after they have been pushed?
问题描述
这可以很好地解释压缩多个提交:
http://git-scm.com/book/en/Git-Branching-Rebasing
但它确实不适用于已经推送的提交。如何在我的本地和远程回购中压缩最近的几次提交?
$ b 编辑:当我做
git rebase -i origin / master〜4 master
,将第一个保存为 pick
,将其他三个保存为 squash
,然后退出(通过emacs中的cx cc ),我得到: $ git rebase -i origin / master〜4 master
#当前没有任何分支。
没有提交(工作目录清理)
无法应用2f40e2c ...还原问题4427:添加了bpf设备权限更改选项
$ git rebase -i origin / master〜4 master
交互式rebase已经开始
其中2f40是选择
提交。现在4个提交中没有一个出现在 git log
中。我希望我的编辑器能够重新启动,以便我可以输入提交消息。我在做什么错了?
壁球在本地提交
git rebase -i origin / master〜4 master
然后使用
git push origin + master
- force
和 +之间的区别 code>
从 git push
:
$ b
请注意
- force
适用于所有被推入的ref,因此使用
它与push.default
设置为匹配
或与配置有remote。*。push
的多个推式
目的地可能会覆盖其他
的refs分支(包括严格落后于
远程对手的本地参考)。要强制推送到一个分支,在refspec前面使用+
来推送(例如git push origin + master
强制
a推到master
分支)。
This gives a good explanation of squashing multiple commits:
http://git-scm.com/book/en/Git-Branching-Rebasing
but it does not work for commits that have already been pushed. How do I squash the most recent few commits both in my local and remote repos?
EDIT: When I do git rebase -i origin/master~4 master
, keep the first one as pick
, set the other three as squash
, and then exit (via c-x c-c in emacs), I get:
$ git rebase -i origin/master~4 master
# Not currently on any branch.
nothing to commit (working directory clean)
Could not apply 2f40e2c... Revert "issue 4427: bpf device permission change option added"
$ git rebase -i origin/master~4 master
Interactive rebase already started
where 2f40 is the pick
commit. And now none of the 4 commits appear in git log
. I expected my editor to be restarted so that I could enter a commit message. What am I doing wrong?
Squash commits locally with
git rebase -i origin/master~4 master
and then force push with
git push origin +master
Difference between --force
and +
From the documentation of git push
:
Note that
--force
applies to all the refs that are pushed, hence using it withpush.default
set tomatching
or with multiple push destinations configured withremote.*.push
may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart). To force a push to only one branch, use a+
in front of the refspec to push (e.ggit push origin +master
to force a push to themaster
branch).
这篇关于如何压扁git后提交git?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!