Web lists-archives.com

Re: Tools that do an automatic fetch defeat "git push --force-with-lease"

On Fri, Apr 7, 2017 at 7:15 PM, Matt McCutchen <matt@xxxxxxxxxxxxxxxxx> wrote:
> When I'm rewriting history, "git push --force-with-lease" is a nice
> safeguard compared to "git push --force", but it still assumes the
> remote-tracking ref gives the old state the user wants to overwrite.
> Tools that do an implicit fetch, assuming it to be a safe operation,
> may break this assumption.  In the worst case, Visual Studio Code does
> an automatic fetch every 3 minutes by default [1], making
> --force-with-lease pretty much reduce to --force.

Isn't the point of force-with-lease to actually record a "commit" id,
and not pass it a branch name, but actually the sha1 you intend the
remote server to be at? Sure if you happen to pass it a branch or
remote name it will interpret it for yuou, but you should be able to
do something like

current=$(git rev-parse origin/branch)
<verify current is correct and then do your rewind stuff>
git push --force-with-lease=$current

and this will work regardless of when if if you fetch in between?