Re: Tools that do an automatic fetch defeat "git push --force-with-lease"
- From
Jacob Keller <jacob.keller@gmail.com>
- Date
- Apr 8, 2017, 08:25 UTC
- Message-ID
- <CA+P7+xrVe7jnqpQFvYBb25ofrNqnRspdk-M6jRuwRi5sUqCCZg@mail.gmail.com>
- In-Reply-To
- <1491617750.2149.10.camel@mattmccutchen.net>
On Fri, Apr 7, 2017 at 7:15 PM, Matt McCutchen <matt@mattmccutchen.net> wrote:
Show 8 quoted lines
> 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?
Thanks, Jake