git - Git push atomically, only if the target branch is at the expected SHA
问题描述
Is there a way to push to a branch only if it hasn't changed since I last fetched it?
More specifically, I'd like to delete branches that have already been merged, but only if no one else pushes new commits to them between when I check that the branch has been merged and when I push the deletion.
From the git push
documentation, I see that it does support a --atomic
option, but that option is for making updates to multiple branches atomically with respect to each other, rather than for ensuring that my update to a remote branch will be atomic with respect to other users' updates.
Ie, I want to delete merged branches on a remote git repository without any risk of deleting anyone else's work, even if they are working concurrently.
解决方案
是的,这可以通过使用该--force-with-lease
选项来实现。例如:
$ git push --force-with-lease=refs/heads/foo origin :refs/heads/foo
这是为强制推送而设计的,但也适用于删除。该选项有许多变体,如果您愿意,可以采用显式值。
推荐阅读
- javascript - PHP 内部服务器错误 500,对 PHP 的 Javascript 调用给出错误
- postgresql - 运算符不存在整数:refcursor,42883 | Postgres
- android - Google Fit API:存储心率 bmp 数据点
- c# - c# selenium image xpath下载
- javascript - Javascript 似乎不适用于移动设备
- c# - 如何在 foreach 循环中的每次迭代后进行延迟?
- python - 找不到GDAL模块
- vue.js - 回到vue中的页面后currentPage的状态正在改变
- powershell - 最大化 Chrome 窗口
- objective-c - Obj-C - 以编程方式将 NSWindow Appearance 设置为 NSAppearanceNameVibrantDark,不起作用