使用git获取或拉取自动修剪 [英] Automatic prune with git fetch or pull
问题描述
如果有人因为工作结束而删除了一个远程分支,我不知道,我不会执行 git fetch --prune
,最终我会推送返回已删除的分支。
有没有一种可行的解决方案可以强制git在取/拉时使用修剪模式,而无需每次指定它?
git fetch
(因此git pull
)学会检查fetch.prune
和remote。*。prune
配置变量,并表现得像- prune $ c
这意味着,如果您将remote.origin.prune设置为true: p>
git config remote.origin.prune true
任何 git fetch
或 git pull
会自动修剪。
注意:Git 2.12(2017年第1季度)将修复与此配置有关的错误,这会使 git remote rename
misbehave。
请参阅如何重命名git remote? 。
更多信息请参见 commit 737c5a9 :
$ b
没有
git fetch --prune
,远程跟踪分支,另一方已经移除的分支将永远保留。
有些人总是想要运行git fetch --prune
。
为了适应希望总是修剪或从特定远程获取的用户,添加两个新配置变量
fetch.prune
和remote。< name> .prune
:
>
fetch.prune
允许为所有提取操作启用修剪。 >
remote。< name> .prune
允许更改每个远程的行为。
后者自然会覆盖前者,命令行中的
- [no-] prune
选项将覆盖因为- prune
是潜在的破坏性操作(Git不会保留已删除引用的reflogs但是),我们不希望在没有用户同意的情况下修剪,因此此配置默认情况下不会启用。
If someone deleted a remote branch because the work is over and I don't know, I won't do a git fetch --prune
and eventually I will push back the deleted branch.
Is there a viable solution for forcing git to use the prune mode when fetching / pulling without having to specify it every time?
"
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.
That means that, if you set remote.origin.prune to true:
git config remote.origin.prune true
Any git fetch
or git pull
will automatically prune.
Note: Git 2.12 (Q1 2017) will fix a bug related to this configuration, which would make git remote rename
misbehave.
See "How do I rename a git remote?".
See more at 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获取或拉取自动修剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!