本文介绍了`git push --force`的其他后果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有关强制执行 git push 的问题和答案不难找到(推送到回购 - 执行后git-commit-amend> 2个)。标准答案如下所示: 我认为这是一般的忠告 - 更安全的路线是再次提交,修复任何问题你打破了。但是让我们说,例如我知道(神奇地)没有人已经提交了提交。或者更好的是,这是一个私人回购,所以没有打破任何人的克隆的危险。 有没有其他 - 强制推动的[负面]后果,特别是技术后果?也许它会在远程造成一些额外的垃圾,或者破坏X Corps的分析工具1.2.3版本,或者使得重新绑定更容易混淆,等等。什么? 编辑1:我有我自己的轶事证据表明 - 强制推动私人回购不会似乎导致任何问题。虽然我对知觉不感兴趣,我正在寻找引用和/或这样的证明。 解决方案强制推送只是告诉远程移动给定即使移动不是快进操作,标签也是如此。非快进可以(不一定)导致放弃提交:不再可达的提交一些参考文献。 当标签运动出现在其他地方引用的图的一部分时执行此操作。例如,如果分支 xyzzy 指向以下顺序提交 D : ABCE $ / D 那么标签 xyzzy 会发生什么,因为标签 plugh 使提交 D 可达,因此以非快进方式移动 xyzzy ,例如指向提交 C 不会影响提交 D 。 se,删除标签 xyzzy 完全也是无害的,至少在提交图结构方面是这样。) 远程裸仓库(通常会向其推送)通常不会记录所有ref更新,因此这往往会触发对任何已放弃的提交的快速垃圾回收。 (请注意,如果您将它们保留在自己的存储库中,则可以稍后恢复gc'ed提交 - 但这需要您通过网络再次发送数据,并且如果您自己的repo被损坏,则可能导致数据丢失风险,电源故障或电脑着火。) 如果您有一些第三方软件假定(部分或全部)分支标签只能快速移动这种软件可能会以有趣的方式失败。我知道没有这样的软件,如果它存在,我会称它为破碎,但人们似乎经常写破碎的代码,然后依赖它。 老版本的git允许标签在移动快进时不用强制推送就移动,就像分支标签预期移动一样。较新的版本(我认为在1.8.2中介绍过,但这只是从内存中获得)拒绝任何标签运动,除非您使用强制。当然,你可以随时删除,然后重新创建(可能在不同的地方)一个标签,内置的钩子就可以。因此,还有其他方式可以以任意方式移动标签或分支,即使没有力量。只需确保要保留的提交图的各个部分在每个操作中都有 标签即可。 至于使得(你自己的)重新绑定更难:是的,它可以有这种效果,因为你可能会从桌面强制推送,因此,实际上,重新排列共享裸-repo。后来,在笔记本电脑上,您可能无法记住提交给您的是哪个,找出它可能有点棘手,尤其是在大型,高度活跃的存储库中。 幸运的是,即将推出的新git版本具有一项新功能,该功能会使用您的reflog来确定是否以及何时发生上游重新贷款。也就是说,在上述情况下,您可以(在笔记本电脑上)让git自动发现共享裸回购中的哪些提交已重新分配,以及重新分配您的笔记本电脑工作。 (这是现在在git 1.8.x中对 git pull --rebase 使用的方法的概括。) Questions and answers about forcing a git push aren't hard to find (here are two). The standard answer goes something like this:I see this as generally sage advice - the safer route is to just commit again, fixing whatever you broke. But let's say for example I know (magically) that no one has pulled the commit(s) yet. Or better still, that this is a private repo and so there's no danger of breaking anyone else's clone in the first place.Are there any other [negative] consequences of --forceing a push, specifically technical consequences? Maybe it causes some extra garbage in the remote, or it breaks version 1.2.3 of X Corps' analysis tool, or it makes rebasing more confusing later on, etc.. Anything?EDIT 1: I have my own anecdotal evidence suggesting that --forceing a push on a private repo doesn't seem to cause any problems. I'm not interested in perception, though; I'm looking for references and/or proof of such. 解决方案 A force-push merely tells the remote to move the given label(s) even if the move is not a fast-forward operation. A non-fast-forward can (does not necessarily) result in "abandoned" commits: commits that are no longer reachable from some reference.(It does not do this when the label motion occurs on a part of the graph that is referenced elsewhere. For instance, if branch xyzzy points to commit D in the sequence:A-B-C-E <-- plugh \ / D <-- xyzzythen it is irrelevant what happens to label xyzzy, as label plugh makes commit D reachable. So moving xyzzy in a non-fast-forward fashion to, e.g., point to commit C does not affect commit D at all. Likewise, deleting label xyzzy entirely is also harmless, at least in terms of the commit graph structure.)Remote bare repositories (to which one generally pushes) often do not log all ref updates, so this tends to trigger rapid garbage-collection of any abandoned commits. (Note that if you keep them in your own repository, you can restore gc'ed commits later—but that requires that you send the data over the network again, and exposes you to data loss risk if your own repo gets corrupted via, say, a power failure, or your computer catching on fire.)If you have some third-party software that assumes that (some or all) branch labels only move in fast-forward fashion, said software could fail in interesting ways. I know of no such software and if it exists I would call it "broken", but people do often seem to write broken code and then depend on it.Older versions of git allowed tags to move without a force-push if the move was fast-forward, in the same way that branch labels are expected to move. Newer versions (I think introduced in 1.8.2, but that's just from memory) reject any tag motion unless you use force. Of course you can always delete, then re-create (possibly at a different point), a label, and the built-in hook is OK with that. So there are other ways to move a tag or branch, in arbitrary fashion, even without force. Just make sure the parts of the commit graph you want to retain have some label across each operation.As for making (your own) rebasing harder later: yes, it can have that effect, because you might force-push from "desktop" and thus, in effect, rearrange "shared-bare-repo". Later, on "laptop", you might not be able to remember just which commits you rebased, and figuring it out can be a little tricky, especially in a large, highly-active repository.Fortunately, the new upcoming git release has a new feature that uses your reflogs to figure out if and when an "upstream rebase" has occurred. That is, in the above situation, you would be able (on "laptop") to ask git to automatically discover which commits were rebased in shared-bare-repo and "re-rebase" your laptop work on that. (This is a generalization of the method used with git pull --rebase today, in git 1.8.x.) 这篇关于`git push --force`的其他后果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-04 20:44