如果有人因为工作结束而删除了远程分支,我不知道,我不会执行git fetch -prune,最终我会推回已删除的分支。
是否有一个可行的解决方案来强制Git在获取/提取时使用修剪模式,而不必每次都指定它?
如果有人因为工作结束而删除了远程分支,我不知道,我不会执行git fetch -prune,最终我会推回已删除的分支。
是否有一个可行的解决方案来强制Git在获取/提取时使用修剪模式,而不必每次都指定它?
当前回答
最终我将推回删除的分支
这是我认为你应该解决的问题。如果你配置了git,让它推送你不想推送的分支,这可能是个问题。我个人更倾向于只在显式指定想要推送的分支时才推送分支。
有关如何在git存储库中配置推送设置的指导,请参阅https://stackoverflow.com/a/948397/3753318。
其他回答
如果你想总是修剪当你取回,我可以建议使用别名。
只需输入git config -e打开编辑器,更改特定项目的配置,并添加如下部分
[alias]
pfetch = fetch --prune
当你获取与git pfetch修剪将自动完成。
从git 1.8.5(2013年第四季度)开始:
“git fetch”(因此“git pull”也是如此)学会了检查“fetch”。修剪”和“远程。*”。修剪”配置变量,使其行为与给出的命令行选项“——Prune”相同。
这意味着,如果你设置remote.origin.prune为true:
git config remote.origin.prune true
任何git获取或git拉将自动修剪。
注意:Git 2.12(2017年第一季度)将修复与此配置相关的错误,该错误会使Git远程重命名行为不当。 参见“如何重命名git远程?”。
参见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配置——全局获取。删除真的
always -prune for git fetch and git pull in your git repository:
git config --global fetch.prune true
上面的命令在全局Git配置(通常是~/.gitconfig)中追加了以下几行。使用git config -e——global查看全局配置。
[fetch]
prune = true
Git配置remote.origin.prune为true
总是从一个存储库中修剪:
git config remote.origin.prune true
#^^^^^^
#replace with your repo name
上面的命令在您的本地Git配置(通常是. Git /config)中添加下面最后一行。使用git config -e查看本地配置。
[remote "origin"]
url = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
fetch = +refs/heads/*:refs/remotes/origin/*
prune = true
您还可以在第二个命令中使用——global,或者在第一个命令中使用——local。
Git配置——全局gui。pruneDuringFetch真实
如果你使用git gui,你可能也会感兴趣:
git config --global gui.pruneDuringFetch true
附加:
[gui]
pruneDuringFetch = true
参考文献
git帮助配置中的对应文档:
——全球 对于写入选项:write to global ~/。如果存在$XDG_CONFIG_HOME/git/config文件,则写入~/. gitconfig文件,而不是存储库的.git/config文件。Gitconfig文件没有。
——当地 对于写入选项:写入存储库的.git/config文件。这是默认行为。
fetch.prune 如果为true, fetch将自动执行——prune选项,就像在命令行中给出的一样。参见remote.<name>.prune。
gui.pruneDuringFetch 如果git-gui在执行取回时应该修剪远程跟踪分支,则为true。系统默认值为false。
遥远。<名称> .prune 当设置为true时,默认情况下,从这个远程获取也将删除远程上不再存在的任何远程跟踪引用(就像在命令行上给出了——prune选项一样)。覆盖取回。修剪设置,如果有的话。
最终我将推回删除的分支
这是我认为你应该解决的问题。如果你配置了git,让它推送你不想推送的分支,这可能是个问题。我个人更倾向于只在显式指定想要推送的分支时才推送分支。
有关如何在git存储库中配置推送设置的指导,请参阅https://stackoverflow.com/a/948397/3753318。