本文介绍了git push --force-with-lease vs. --force的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解两者之间的区别

I am trying to understand the difference between

git push --force

git push --force-with-lease

我的猜测是,如果远程没有提交本地分支没有的提交,则后者只会推送到远程?

My guess is that the latter only pushes to the remote if the remote does not have commits that the local branch doesn't have?

推荐答案

force用您的本地分支覆盖远程分支.

force overwrites a remote branch with your local branch.

--force-with-lease是一个更安全的选项,如果更多的提交(由另一个团队成员或同事或您拥有的东西)添加到远程分支,则不会覆盖远程分支上的任何工作.这样可以确保您不会通过强行覆盖其他人的工作.

--force-with-lease is a safer option that will not overwrite any work on the remote branch if more commits were added to the remote branch (by another team-member or coworker or what have you). It ensures you do not overwrite someone elses work by force pushing.

我认为您对命令的总体了解是正确的.如果远程分支与本地计算机上的远程分支具有相同的值,则将覆盖远程.如果没有相同的值,则表示您在处理代码时其他人对远程分支进行了更改,因此不会覆盖任何代码.显然,如果远程有其他提交,则值将不同.

I think your general idea surrounding the command is correct. If the remote branch has the same value as the remote branch on your local machine- you will overwrite remote. If it doesn't have the same value- it indicates a change that someone else made to the remote branch while you were working on your code and thus will not overwrite any code. Obviously if there are additional commits in remote then the values won't be the same.

我只是想将--force-with-lease用作要确保不会覆盖任何队友代码的选项.我公司的许多团队都将--force-with-lease用作故障保护的默认选项.在大多数情况下,这是不必要的,但是如果您碰巧覆盖了另一个人贡献给远程用户的内容,则将为您省去很多麻烦.

I just think of --force-with-lease as the option to use when I want to make sure I don't overwrite any teammates code. A lot of teams at my company use --force-with-lease as the default option for a fail-safe. Its unnecessary in most circumstances but will save you lots of headache if you happen to overwrite something that another person contributed to remote.

我确定您已经看过文档,但是这里可能包含一些冗长的解释:

I'm sure you looked at the docs but there might be some more wordy explanation contained in here:

https://git-scm.com/docs/git-push

这篇关于git push --force-with-lease vs. --force的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:44