简体   繁体   English

git rebase-我挤压没有删除提交

[英]Git rebase - i squashing didn't remove commit

I have a local commit after origin master's head, and want to combine last two commits. 我在原产地主管的头后面有一个本地提交,并且想要合并最后两个提交。 So suppose the history is as follows: 因此,假设历史如下:

* e9199ba - (HEAD -> master)
|           test
* c4e3b53 - (origin/master, origin/HEAD)
|           Saturn ring angle change in X and Y

And want to make one commit instead of e9199ba and c4e3b53 . 并且想要提交一次提交,而不是e9199bac4e3b53 I did git git rebase -i HEAD~2 and squashed the second commit: 我做了git git rebase -i HEAD~2并压缩了第二个提交:

pick c4e3b53 Saturn ring angle change in X and Y
squash e9199ba test

As a result I've got two independent commits - the new squashed one and old master's one: 结果,我得到了两个独立的提交-新的提交和旧的提交:

* 216b314 - (HEAD -> master)
|           Suqashed commits
| * c4e3b53 - (origin/master, origin/HEAD)
|/            Saturn ring angle change in X and Y

What's wrong here? 怎么了 Is it by the reason of the origin master's head? 是因为原产地负责人的头吗? How to combine them in this case? 在这种情况下如何合并它们? Or maybe there is some history showing issue? 也许有一些历史显示问题?

Just as you said: 就像你说的:

... I've got two independent commits - the new squashed one and old master's one ...我有两个独立的提交-新压缩的一个和老主人的一个

which is what you should expect, since git rebase works by copying commits (perhaps with some modifications along the way, such as squashing), then having your Git point your own branch name to the new copies. 这是您应该期望的,因为git rebase通过复制提交(也许在此过程中进行了一些修改,例如压榨)来工作,然后让Git将您自己的分支名称指向新副本。

But origin/master is not your own, rebased, branch. 但是origin/master不是您自己的,基于基础的分支。 It's your remote-tracking branch, and it remembers what some other Git has in that other Git's master . 这是您的远程跟踪分支,它会记住其他一些Git在该其他 Git的master Hence your origin/master continues to remember what that other Git has, which is the original commits before you made slightly-modified copies. 因此,您的origin/master继续记住其他Git所具有的功能,这是在您进行稍微修改的副本之前的原始提交。

That other Git repository itself—the one you call origin —has the other commit. 另一个Git存储库本身(您称为origin具有另一个提交。 Since origin has it, anyone who has copied from origin also has it. 由于具有origin ,因此从origin复制的任何人也都具有origin You must convince origin , and anyone who has copied from origin , to switch over to your shiny new commits. 您必须说服origin以及所有从origin复制过来的origin ,才能切换到新的提交。

If you have control over origin , you can likely use a "force push" to overwrite whatever it has now in its master with your shiny new commits. 如果你有控制权origin ,可以很可能使用“力推”覆盖不管它现在已经在其master与你闪亮的新的提交。 (The origin repository will still have the old commit too, though perhaps very briefly until it does a "garbage collection" pass.) Then you must also convince all users of origin to switch, too, just like you did and just like you forced origin to do. origin存储库也仍然具有旧的提交,尽管可能很短暂,直到它进行“垃圾收集”通过为止。)然后,您还必须说服所有 origin用户进行切换,就像您所做的一样,就像您被强制执行一样origin做。 Exactly how you can and will do that is up to you. 确切的方式和方式取决于您。

Note that if other people are also pushing to origin , it's possible that your force-push will wipe away commits they have added, that depend on c4e3b53 . 请注意,如果其他人也在推动origin ,那么您的强制推送可能会抹去他们添加的依赖c4e3b53 You should coordinate with these other people before force-pushing. 您应该在推力之前与其他人进行协调。 (If there are no such other people, that makes the coordination a lot easier.) (如果没有这样的其他人,则使协调更加容易。)

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

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