On Sat, Apr 08, 2017 at 01:25:43AM -0700, Jacob Keller wrote: > 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? That's definitely the _best way to do it (modulo using "branch:$current" in the final command). I think Matt's point is just that the default, to use origin/branch, is unsafe. It's convenient when you don't have extra fetches, but that convenience may not be worth the potential surprise. -Peff