简体   繁体   English

git rebase后缺少​​git push中的+参数

[英]Missing the + parameter in git push after git rebase

I want to squash commits in git after they have been pushed. 我想在推送完成后将提交压缩到git中。 So I find the question How to squash commits in git after they have been pushed? 因此,我发现了一个问题: 如何在推送后将其压缩到git中? .

I do as the accepted answer said: 我按照公认的回答说:

git rebase -i origin/master~4 master

But I forget to add the + parameter before the master while pushing it to github. 但是我忘记了在将其推到github时在主节点之前添加+参数。 It means I use git push origin master rather than git push origin +master . 这意味着我使用git push origin master而不是git push origin +master

I want to know does it matter much and how to undo that so I can use the right command. 我想知道这有多重要,以及如何撤消它,所以我可以使用正确的命令。

------------------- EDIT1 ---------------------------- ------------------- 编辑1 ----------------------------

I use emacs magit as my git client, so specificly speaking, I use magit-push-other origin master . 我使用emacs magit作为我的git客户端,因此具体地说,我使用magit-push-other origin master

Magit's log is below, the red rectangle circles two commits I want to squash. Magit的日志在下面,红色矩形圈出了我要压缩的两个提交。 After I squash that two commits, magit informs me that there are one commit unpushed and two commits unmerged from upstream. 在我压扁了两个提交之后,magit告诉我有一个未推送的提交和两个未从上游合并的提交。 Then I use magit-pull-from-upstream and magit-push-other origin master to complete those changes. 然后,我使用magit-pull-from-upstreammagit-push-other origin master完成这些更改。 Then the commit log is what the picture draws. 然后提交日志就是图片绘制的内容。

magit日志

If git push origin master wouldn't work at this situation, it seems it's more like a magit question. 如果git push origin master在这种情况下不起作用,似乎更像是一个magit问题。

As @rkta pointed out, the problem was created when you did a pull after squashing: you'll notice that your Git log now has three commits to edit your grammatical errors: the original two, plus the squashed one, merged together into c6f979b . 正如@rkta所指出的,这个问题是在您挤压后进行拉动时产生的:您会注意到,您的Git日志现在具有三个提交来编辑语法错误:原始的两个加上已压缩的一次,合并到c6f979b That merge commit was created by git pull . 该合并提交是由git pull创建的。

At this point, I recommend you not try to fix this problem, as your collaborators have probably fetched your changes and they will have to do some work to fix their sandboxes if you try to fix this history again. 此时,我建议您不要尝试解决此问题,因为您的协作者可能已经获取了您的更改,如果您再次尝试修复此历史记录,他们将不得不做一些工作来修复其沙箱。 In general, from the moment you push a commit, I would say you should let the history stand even if you don't like it - force pushing only makes more work for others. 总的来说,从您提交承诺的那一刻起,我想说即使您不喜欢它也应该保留历史-强制推送只会为他人带来更多工作。

That being said, here's how you could still fix it, and how you could have fixed it in the first place: 话虽如此,这是您仍然可以修复它的方式,以及首先如何修复它的方法:

git pull
git rebase -i a8ba675
# mark the grammatical error commits to be squashed -
# this will still work even though you already merged
git fetch
# use git log --all to make sure no one committed anything since the pull above
git push origin +master
# pray no one comes to yell at you

What to do if you forget the + parameter 如果忘记了+参数怎么办

The + means to do a force push. +表示强制推动。 If you forget it in a case where it is needed, you'll get an error message. 如果您在需要时忘记了它,则会收到错误消息。 Solution then is to do it again with + . 解决的方法是再次使用+

But you should really learn more about rewriting history in git before using techniques like that. 但是在使用类似技术之前,您应该真正了解有关在git中重写历史记录的更多信息。

Rule of thumb: Don't rewrite history after you pushed -- this means you probably never need to force push. 经验法则:不要在推送后重写历史记录-这意味着您可能永远不需要强制推送。


Why didn't you get an error and why was the result not as expected? 为什么没有收到错误,为什么结果没有达到预期?

Problem is, that you did a pull after the squash. 问题是,您在壁球之后做了拉力。

Why is git showing that there is one commit unpushed and two commits unmerged from upstream? 为什么git会显示从上游推送了一个提交而没有合并两个提交呢?

You created two commits A and B and pushed those to origin. 您创建了两个提交A和B,并将它们推到原始位置。 Now, when you squash those commits locally both get deleted and replaced by a new commit C. 现在,当您在本地压缩这些提交时,它们都将被删除,并被新的提交C代替。

Then git sees two commits (A and B) on origin which are not in your history -- of course, you just deleted them. 然后git在原始记录中看到两个不在源中的提交(A和B)-当然,您只是删除了它们。 If you do a git pull , your just deleted commits and the newly created one are merged together. 如果执行git pull ,则刚刚删除的提交和新创建的提交将合并在一起。

Solution 1: 解决方案1:

Don't rewrite history once it got pushed! 一旦推送历史,请勿重写历史!

Solution 2: 解决方案2:

Don't pull after squashing commits, just force push. 挤压提交后不要拉,只需强行推动即可。 Really don't do this with shared branches! 真的不要对共享分支执行此操作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM