gpt4 book ai didi

git - 使用 Git 获取或 pull 自动修剪

转载 作者:IT王子 更新时间:2023-10-29 01:15:07 26 4
gpt4 key购买 nike

如果有人因为工作结束而删除了一个远程分支,而我不知道,我不会执行 git fetch --prune,最终我会推回删除的分支。

是否有可行的解决方案来强制 Git 在获取/pull 时使用修剪模式而不必每次都指定它?

最佳答案

Since git 1.8.5 (Q4 2013) :

"git fetch" (hence "git pull" as well) learned to check "fetch.prune" and "remote.*.prune" configuration variables and to behave as if the "--prune" command line option was given.

这意味着,如果您将 remote.origin.prune 设置为 true:

git config remote.origin.prune true

任何git fetchgit pull会自动剪枝。

注意:Git 2.12(2017 年第一季度)将修复与此配置相关的错误,这会使 git remote rename行为不端。
参见“How do I rename a git remote?”。


查看更多信息 commit 737c5a9 :

Without "git fetch --prune", remote-tracking branches for a branch the other side already has removed will stay forever.
Some people want to always run "git fetch --prune".

To accommodate users who want to either prune always or when fetching from a particular remote, add two new configuration variables "fetch.prune" and "remote.<name>.prune":

  • "fetch.prune" allows to enable prune for all fetch operations.
  • "remote.<name>.prune" allows to change the behaviour per remote.

The latter will naturally override the former, and the --[no-]prune option from the command line will override the configured default.

Since --prune is a potentially destructive operation (Git doesn't keep reflogs for deleted references yet), we don't want to prune without users consent, so this configuration will not be on by default.

关于git - 使用 Git 获取或 pull 自动修剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18308535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com