假设我有这样的代码:
git fetch && git diff origin origin/master --quiet || echo "untracked"
我希望它定期运行。比方说,每秒一次,或每五秒一次,依此类推。
如果此代码输出“untracked”,或者换句话说,如果远程有更新,我将运行 git pull
来更新本地代码。
问题是:做这样的事情不好吗?我的意思是,我知道这将是对远程服务器的持续请求。但是,不好吗?除此之外,还有其他副作用吗?非常感谢。
最佳答案
如果执行得太频繁,除了会使其他命令失败之外,常规提取的主要缺点是 push --force-with-lease
.
我在“ push --force-with-lease
by default”中记录了同样多的内容
--force-with-lease
or--force-with-lease=<refname>
interacts very badly with anything that implicitly runsgit fetch
on the remote to be pushed to in the background, e.g.git fetch origin
on your repository in a cronjob.The protection it offers over
--force
is ensuring that subsequent changes your work wasn't based on aren't clobbered, but this is trivially defeated if some background process is updating refs in the background.
关于git - 定期 git fetch 的副作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49948894/